Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/fontweight number value #34598

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Libraries/StyleSheet/StyleSheetTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,16 @@ export type ____FontWeight_Internal =
| '600'
| '700'
| '800'
| '900';
| '900'
| 100
| 200
| 300
| 400
| 500
| 600
| 700
| 800
| 900;

export type ____TextStyle_InternalCore = $ReadOnly<{
...$Exact<____ViewStyle_Internal>,
Expand Down
11 changes: 9 additions & 2 deletions Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Platform from '../Utilities/Platform';
import * as PressabilityDebug from '../Pressability/PressabilityDebug';
import usePressability from '../Pressability/usePressability';
import StyleSheet from '../StyleSheet/StyleSheet';
import flattenStyle from '../StyleSheet/flattenStyle';
import processColor from '../StyleSheet/processColor';
import TextAncestor from './TextAncestor';
import {NativeText, NativeVirtualText} from './TextNativeComponent';
Expand Down Expand Up @@ -176,6 +177,12 @@ const Text: React.AbstractComponent<
default: accessible,
});

let flattenedStyle = flattenStyle(style);

if (typeof flattenedStyle?.fontWeight === 'number') {
flattenedStyle.fontWeight = flattenedStyle.fontWeight.toString();
}

return hasTextAncestor ? (
<NativeVirtualText
{...restProps}
Expand All @@ -184,7 +191,7 @@ const Text: React.AbstractComponent<
isPressable={isPressable}
numberOfLines={numberOfLines}
selectionColor={selectionColor}
style={style}
style={flattenedStyle}
ref={forwardedRef}
/>
) : (
Expand All @@ -200,7 +207,7 @@ const Text: React.AbstractComponent<
isHighlighted={isHighlighted}
numberOfLines={numberOfLines}
selectionColor={selectionColor}
style={style}
style={flattenedStyle}
ref={forwardedRef}
/>
</TextAncestor.Provider>
Expand Down
9 changes: 9 additions & 0 deletions packages/rn-tester/js/examples/Text/TextExample.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,15 @@ class TextExample extends React.Component<{...}> {
<Text style={{fontWeight: '300'}}>FONT WEIGHT 300</Text>
<Text style={{fontWeight: '200'}}>FONT WEIGHT 200</Text>
<Text style={{fontWeight: '100'}}>FONT WEIGHT 100</Text>
<Text style={{fontWeight: 900}}>FONT WEIGHT 900</Text>
<Text style={{fontWeight: 800}}>FONT WEIGHT 800</Text>
<Text style={{fontWeight: 700}}>FONT WEIGHT 700</Text>
<Text style={{fontWeight: 600}}>FONT WEIGHT 600</Text>
<Text style={{fontWeight: 500}}>FONT WEIGHT 500</Text>
<Text style={{fontWeight: 400}}>FONT WEIGHT 400</Text>
<Text style={{fontWeight: 300}}>FONT WEIGHT 300</Text>
<Text style={{fontWeight: 200}}>FONT WEIGHT 200</Text>
<Text style={{fontWeight: 100}}>FONT WEIGHT 100</Text>
</RNTesterBlock>
<RNTesterBlock title="Font Style">
<Text style={{fontStyle: 'italic'}}>Move fast and be italic</Text>
Expand Down
9 changes: 9 additions & 0 deletions packages/rn-tester/js/examples/Text/TextExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,15 @@ exports.examples = [
<Text style={{fontWeight: '300'}}>FONT WEIGHT 300</Text>
<Text style={{fontWeight: '200'}}>FONT WEIGHT 200</Text>
<Text style={{fontWeight: '100'}}>FONT WEIGHT 100</Text>
<Text style={{fontWeight: 900}}>FONT WEIGHT 900</Text>
<Text style={{fontWeight: 800}}>FONT WEIGHT 800</Text>
<Text style={{fontWeight: 700}}>FONT WEIGHT 700</Text>
<Text style={{fontWeight: 600}}>FONT WEIGHT 600</Text>
<Text style={{fontWeight: 500}}>FONT WEIGHT 500</Text>
<Text style={{fontWeight: 400}}>FONT WEIGHT 400</Text>
<Text style={{fontWeight: 300}}>FONT WEIGHT 300</Text>
<Text style={{fontWeight: 200}}>FONT WEIGHT 200</Text>
<Text style={{fontWeight: 100}}>FONT WEIGHT 100</Text>
</View>
);
},
Expand Down