Skip to content

Commit c7256cb

Browse files
authored
fix(mobile): svg circle support (#2874)
1 parent ea1c666 commit c7256cb

File tree

7 files changed

+36
-15
lines changed

7 files changed

+36
-15
lines changed

apps/mobile/src/icons/loading_3_cute_li.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react"
2-
import Svg, { Path } from "react-native-svg"
2+
import Svg, { Circle, Path } from "react-native-svg"
33

44
interface Loading3CuteLiIconProps {
55
width?: number
@@ -14,6 +14,7 @@ export const Loading3CuteLiIcon = ({
1414
}: Loading3CuteLiIconProps) => {
1515
return (
1616
<Svg width={width} height={height} fill="none" viewBox="0 0 24 24">
17+
<Circle cx={12} cy={12} r={9} stroke={color} strokeWidth={1.5} opacity={0.1} />
1718
<Path
1819
stroke={color}
1920
strokeLinecap="round"

apps/mobile/src/icons/loading_3_cute_re.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react"
2-
import Svg, { Path } from "react-native-svg"
2+
import Svg, { Circle, Path } from "react-native-svg"
33

44
interface Loading3CuteReIconProps {
55
width?: number
@@ -14,6 +14,7 @@ export const Loading3CuteReIcon = ({
1414
}: Loading3CuteReIconProps) => {
1515
return (
1616
<Svg width={width} height={height} fill="none" viewBox="0 0 24 24">
17+
<Circle cx={12} cy={12} r={9} stroke={color} strokeWidth={2} opacity={0.1} />
1718
<Path
1819
stroke={color}
1920
strokeLinecap="round"
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import * as React from "react"
2-
import Svg from "react-native-svg"
2+
import Svg, { Circle } from "react-native-svg"
33

44
interface RoundCuteFiIconProps {
55
width?: number
66
height?: number
77
color?: string
88
}
99

10-
export const RoundCuteFiIcon = ({ width = 24, height = 24 }: RoundCuteFiIconProps) => {
11-
return <Svg width={width} height={height} fill="none" viewBox="0 0 24 24" />
10+
export const RoundCuteFiIcon = ({
11+
width = 24,
12+
height = 24,
13+
color = "#10161F",
14+
}: RoundCuteFiIconProps) => {
15+
return (
16+
<Svg width={width} height={height} fill="none" viewBox="0 0 24 24">
17+
<Circle cx={12} cy={12} r={10} fill={color} />
18+
</Svg>
19+
)
1220
}
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import * as React from "react"
2-
import Svg from "react-native-svg"
2+
import Svg, { Circle } from "react-native-svg"
33

44
interface RoundCuteReIconProps {
55
width?: number
66
height?: number
77
color?: string
88
}
99

10-
export const RoundCuteReIcon = ({ width = 24, height = 24 }: RoundCuteReIconProps) => {
11-
return <Svg width={width} height={height} fill="none" viewBox="0 0 24 24" />
10+
export const RoundCuteReIcon = ({
11+
width = 24,
12+
height = 24,
13+
color = "#10161F",
14+
}: RoundCuteReIconProps) => {
15+
return (
16+
<Svg width={width} height={height} fill="none" viewBox="0 0 24 24">
17+
<Circle cx={12} cy={12} r={9} stroke={color} strokeWidth={2} />
18+
</Svg>
19+
)
1220
}

apps/mobile/src/icons/user_setting_cute_fi.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export const UserSettingCuteFiIcon = ({
1414
}: UserSettingCuteFiIconProps) => {
1515
return (
1616
<Svg width={width} height={height} fill="none" viewBox="0 0 24 24">
17-
<Path fill="#fff" fillOpacity={0.01} d="M24 0v24H0V0z" />
1817
<Path
1918
fill={color}
2019
d="M11 2a5 5 0 1 0 0 10 5 5 0 0 0 0-10M11 13c-2.395 0-4.575.694-6.178 1.672-.8.488-1.484 1.064-1.978 1.69C2.358 16.976 2 17.713 2 18.5c0 .845.411 1.511 1.003 1.986.56.45 1.299.748 2.084.956C6.665 21.859 8.771 22 11 22c.23 0 .46-.002.685-.005a1 1 0 0 0 .89-1.428A5.973 5.973 0 0 1 12 18c0-1.252.383-2.412 1.037-3.373a1 1 0 0 0-.72-1.557c-.43-.046-.87-.07-1.317-.07M20.616 15.469a1 1 0 1 0-1.732-1l-.336.582a2.995 2.995 0 0 0-1.097-.001l-.335-.581a1 1 0 1 0-1.732 1l.335.58a2.997 2.997 0 0 0-.547.951H14.5a1 1 0 0 0 0 2h.671a3.021 3.021 0 0 0 .549.95l-.336.581a1 1 0 1 0 1.732 1l.336-.581c.359.066.73.068 1.097 0l.335.581a1 1 0 1 0 1.732-1l-.335-.58c.242-.284.426-.607.547-.951h.672a1 1 0 1 0 0-2h-.671a3.029 3.029 0 0 0-.549-.95z"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"reinstall": "rm -rf node_modules && rm -rf apps/**/node_modules && rm -rf packages/**/node_modules && pnpm install",
4545
"start": "electron-vite preview",
4646
"sync:ab": "tsx scripts/pull-ab-flags.ts",
47-
"sync:icons": "tsx scripts/svg-to-rn.ts && prettier --write apps/mobile/src/icons/**/*.tsx",
47+
"sync:icons": "tsx scripts/svg-to-rn.ts && prettier --write apps/mobile/src/icons/**/*.tsx && eslint --fix apps/mobile/src/icons/**/*.tsx",
4848
"test": "cross-env CI=1 pnpm --recursive run test",
4949
"typecheck": "turbo typecheck",
5050
"update:main-hash": "tsx plugins/vite/generate-main-hash.ts"

scripts/svg-to-rn.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface SvgNode {
1313
children?: SvgNode[]
1414
}
1515

16-
const generatePathElement = (node: SvgNode): string => {
16+
const generateElement = (node: SvgNode): string => {
1717
const props = Object.entries(node.properties)
1818
.map(([key, value]) => {
1919
const camelKey = key.replaceAll(/-([a-z])/g, (_match, p1: string) => p1.toUpperCase())
@@ -33,7 +33,9 @@ const generatePathElement = (node: SvgNode): string => {
3333
})
3434
.join(" ")
3535

36-
return ` <Path ${props} />`
36+
const tagName = `${node.tagName.charAt(0).toUpperCase()}${node.tagName.slice(1)}`
37+
38+
return ` <${tagName} ${props} />`
3739
}
3840

3941
const isPureBackgroundPath = (node: any) => {
@@ -45,20 +47,22 @@ const isPureBackgroundPath = (node: any) => {
4547
)
4648
}
4749

50+
const supportedTags = new Set(["path", "circle"])
51+
4852
const convertSvgToRN = (svgContent: string, componentName: string) => {
4953
const ast = parse(svgContent)
5054
const svgNode = ast.children[0] as SvgNode
5155
const { width, height } = svgNode.properties
5256

5357
const pathElements =
5458
svgNode.children
55-
?.filter((child) => child.tagName === "path")
59+
?.filter((child) => supportedTags.has(child.tagName))
5660
.filter((child) => !isPureBackgroundPath(child))
57-
.map((node) => generatePathElement(node))
61+
.map((node) => generateElement(node))
5862
.join("\n") ?? ""
5963

6064
return `import * as React from "react"
61-
import Svg, { Path } from "react-native-svg"
65+
import Svg, { Circle, Path } from "react-native-svg"
6266
6367
interface ${componentName}Props {
6468
width?: number

0 commit comments

Comments
 (0)