panhui 5 лет назад
Родитель
Сommit
4e38783f1e
5 измененных файлов с 43 добавлено и 6 удалено
  1. 0 0
      Utils/SvgUtils.js
  2. 9 0
      Utils/SvgUtilsNew.js
  3. 27 4
      components/SvgIcon.js
  4. 1 1
      components/Text.js
  5. 6 1
      navigation/BottomTabNavigator.jsx

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
Utils/SvgUtils.js


Разница между файлами не показана из-за своего большого размера
+ 9 - 0
Utils/SvgUtilsNew.js


+ 27 - 4
components/SvgIcon.js

@@ -1,18 +1,41 @@
 import * as React from 'react'
 import { svg, path } from 'react-native-svg'
 import { withTheme } from 'react-native-paper'
-import names from '../Utils/SvgUtils'
+import svgMap from '../Utils/SvgUtilsNew'
 
 function Icon(props) {
-  const { name, width, height, type, theme } = props
+  const { name, width, height, type, theme, fillAll } = props
   let { color } = props
   const { colors } = theme
   if (type) {
     color = colors[type]
   }
+  const svgInfo = svgMap.get(name)
+  const viewBox = svgInfo ? svgInfo.viewBox || '0 0 1024 1024' : '0 0 1024 1024'
+  const pathList = svgInfo
+    ? svgInfo.pathList || [
+        {
+          ...svgInfo,
+        },
+      ]
+    : []
+  const pathComList = () => {
+    return pathList.map((item, index) => {
+      const pathProps = { ...item }
+      if (fillAll || !item.fillRule) {
+        pathProps.fill = color
+      }
+
+      if (item.fillRule) {
+        pathProps.stroke = color
+      }
+      delete pathProps.viewBox
+      return <path {...pathProps} key={index} />
+    })
+  }
   return (
-    <svg width={width || 32} height={height || 32} viewBox="0 0 1024 1024">
-      <path fill={color || '#000000'} d={names[name || 'home']} />
+    <svg width={width} height={height} viewBox={viewBox}>
+      {pathComList()}
     </svg>
   )
 }

+ 1 - 1
components/Text.js

@@ -57,7 +57,7 @@ function MyText(props) {
     case 'c2':
       // 10
       return (
-        <Text theme={theme} medium style={[{ fontSize: 10 }, { ...style }]}>
+        <Text theme={theme} style={[{ fontSize: 10 }, { ...style }]}>
           {children}
         </Text>
       )

+ 6 - 1
navigation/BottomTabNavigator.jsx

@@ -20,7 +20,12 @@ export default function BottomTabNavigator() {
             </Text>
           ),
           tabBarIcon: ({ focused }) => (
-            <Icon type={focused ? 'primary' : 'info'} name="home" />
+            <Icon
+              fillAll={!!focused}
+              type={focused ? 'primary' : 'info'}
+              width={37}
+              name="home"
+            />
           ),
         }}
       />

Некоторые файлы не были показаны из-за большого количества измененных файлов