Skip to content

Commit c755355

Browse files
authored
Merge pull request #2120 from Shopify/RefDefault
Make font property mandatory in Text
2 parents 4ee9621 + 387b87b commit c755355

File tree

5 files changed

+5
-37
lines changed

5 files changed

+5
-37
lines changed

docs/docs/text/text.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Please note that the y origin of the Text is the bottom of the text, not the top
1111
| Name | Type | Description |
1212
|:------------|:-----------|:----------------------------------------------------------------|
1313
| text | `string` | Text to draw |
14-
| font | `SkFont` | Font to use (optional) |
14+
| font | `SkFont` | Font to use |
1515
| x | `number` | Left position of the text (default is 0) |
1616
| y | `number` | Bottom position the text (default is 0, the ) |
1717

@@ -30,7 +30,6 @@ export const HelloWorld = () => {
3030
x={0}
3131
y={fontSize}
3232
text="Hello World"
33-
// Font is optional
3433
font={font}
3534
/>
3635
</Canvas>

package/cpp/rnskia/dom/props/FontProp.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,12 @@ class FontProp : public DerivedProp<SkFont> {
3131
"Expected SkFont object or null/undefined for the Font property.");
3232
}
3333
} else {
34-
auto fm = SkFontMgr::RefDefault();
35-
sk_sp<SkTypeface> typeface =
36-
fm->legacyMakeTypeface(nullptr, SkFontStyle());
37-
auto font = std::make_shared<SkFont>(SkFont(typeface));
38-
font->setSize(14);
39-
setDerivedValue(font);
34+
setDerivedValue(nullptr);
4035
}
4136
}
4237

4338
private:
4439
NodeProp *_fontProp;
4540
};
4641

47-
} // namespace RNSkia
42+
} // namespace RNSkia

package/src/dom/nodes/drawings/Text.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,8 @@ export class TextNode extends JsiDrawingNode<TextProps, SkFont | null> {
2323

2424
protected deriveProps() {
2525
const { font } = this.props;
26-
if (font === null) {
27-
return null;
28-
} else if (font === undefined) {
29-
console.warn(
30-
"<Text />: the font property is mandatory on React Native Web"
31-
);
26+
if (!font) {
3227
return null;
33-
// return this.Skia.Font(
34-
// this.Skia.FontMgr.System().matchFamilyStyle("System", {
35-
// width: 5,
36-
// weight: 400,
37-
// slant: 0,
38-
// }),
39-
// 14
40-
// );
4128
}
4229
return font;
4330
}

package/src/dom/types/Drawings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export interface DiffRectProps extends DrawingNodeProps {
109109
}
110110

111111
export interface TextProps extends DrawingNodeProps {
112-
font?: SkFont | null;
112+
font: SkFont | null;
113113
text: string;
114114
x: number;
115115
y: number;

package/src/renderer/__tests__/e2e/Text.spec.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,6 @@ describe("Text", () => {
6969
checkImage(image, `snapshots/text/text-bounds-${surface.OS}.png`);
7070
});
7171

72-
// We test it only on Android and iOS now because there might be no default font on Web
73-
itRunsE2eOnly("The font property is optional", async () => {
74-
const image = await surface.draw(
75-
<>
76-
<Fill color="white" />
77-
<Group>
78-
<Text x={32} y={64} text="Hello World!" />
79-
</Group>
80-
</>
81-
);
82-
checkImage(image, `snapshots/text/text-default-font-${surface.OS}.png`);
83-
});
84-
8572
it("Should draw text along a circle", async () => {
8673
const font = fonts.RobotoMedium;
8774
const { Skia } = importSkia();

0 commit comments

Comments
 (0)