From c7256cb331b0ceb9bf5dd101d7f154a2795dd7e0 Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Mon, 24 Feb 2025 22:58:50 +0800 Subject: [PATCH] fix(mobile): svg circle support (#2874) --- apps/mobile/src/icons/loading_3_cute_li.tsx | 3 ++- apps/mobile/src/icons/loading_3_cute_re.tsx | 3 ++- apps/mobile/src/icons/round_cute_fi.tsx | 14 +++++++++++--- apps/mobile/src/icons/round_cute_re.tsx | 14 +++++++++++--- apps/mobile/src/icons/user_setting_cute_fi.tsx | 1 - package.json | 2 +- scripts/svg-to-rn.ts | 14 +++++++++----- 7 files changed, 36 insertions(+), 15 deletions(-) diff --git a/apps/mobile/src/icons/loading_3_cute_li.tsx b/apps/mobile/src/icons/loading_3_cute_li.tsx index f77df95bd..1c0295654 100644 --- a/apps/mobile/src/icons/loading_3_cute_li.tsx +++ b/apps/mobile/src/icons/loading_3_cute_li.tsx @@ -1,5 +1,5 @@ import * as React from "react" -import Svg, { Path } from "react-native-svg" +import Svg, { Circle, Path } from "react-native-svg" interface Loading3CuteLiIconProps { width?: number @@ -14,6 +14,7 @@ export const Loading3CuteLiIcon = ({ }: Loading3CuteLiIconProps) => { return ( + { return ( + { - return +export const RoundCuteFiIcon = ({ + width = 24, + height = 24, + color = "#10161F", +}: RoundCuteFiIconProps) => { + return ( + + + + ) } diff --git a/apps/mobile/src/icons/round_cute_re.tsx b/apps/mobile/src/icons/round_cute_re.tsx index aea3651c3..460c2a485 100644 --- a/apps/mobile/src/icons/round_cute_re.tsx +++ b/apps/mobile/src/icons/round_cute_re.tsx @@ -1,5 +1,5 @@ import * as React from "react" -import Svg from "react-native-svg" +import Svg, { Circle } from "react-native-svg" interface RoundCuteReIconProps { width?: number @@ -7,6 +7,14 @@ interface RoundCuteReIconProps { color?: string } -export const RoundCuteReIcon = ({ width = 24, height = 24 }: RoundCuteReIconProps) => { - return +export const RoundCuteReIcon = ({ + width = 24, + height = 24, + color = "#10161F", +}: RoundCuteReIconProps) => { + return ( + + + + ) } diff --git a/apps/mobile/src/icons/user_setting_cute_fi.tsx b/apps/mobile/src/icons/user_setting_cute_fi.tsx index 0be3972c1..d97c5c923 100644 --- a/apps/mobile/src/icons/user_setting_cute_fi.tsx +++ b/apps/mobile/src/icons/user_setting_cute_fi.tsx @@ -14,7 +14,6 @@ export const UserSettingCuteFiIcon = ({ }: UserSettingCuteFiIconProps) => { return ( - { +const generateElement = (node: SvgNode): string => { const props = Object.entries(node.properties) .map(([key, value]) => { const camelKey = key.replaceAll(/-([a-z])/g, (_match, p1: string) => p1.toUpperCase()) @@ -33,7 +33,9 @@ const generatePathElement = (node: SvgNode): string => { }) .join(" ") - return ` ` + const tagName = `${node.tagName.charAt(0).toUpperCase()}${node.tagName.slice(1)}` + + return ` <${tagName} ${props} />` } const isPureBackgroundPath = (node: any) => { @@ -45,6 +47,8 @@ const isPureBackgroundPath = (node: any) => { ) } +const supportedTags = new Set(["path", "circle"]) + const convertSvgToRN = (svgContent: string, componentName: string) => { const ast = parse(svgContent) const svgNode = ast.children[0] as SvgNode @@ -52,13 +56,13 @@ const convertSvgToRN = (svgContent: string, componentName: string) => { const pathElements = svgNode.children - ?.filter((child) => child.tagName === "path") + ?.filter((child) => supportedTags.has(child.tagName)) .filter((child) => !isPureBackgroundPath(child)) - .map((node) => generatePathElement(node)) + .map((node) => generateElement(node)) .join("\n") ?? "" return `import * as React from "react" -import Svg, { Path } from "react-native-svg" +import Svg, { Circle, Path } from "react-native-svg" interface ${componentName}Props { width?: number