admin管理员组文章数量:1026912
I'm using React navigation to change screens with the bottom tab navigations, but when I try to use a custom SVG I have many troubles and using an image to show as an icon the color obviously doesn't change, how can I use an SVG file that can recognize the color im passing to change when I'm on the page?
function MyTabs() {
return(
<Tab.Navigator
tabBarOptions={{
showLabel: false,
style:{
backgroundColor:'#313A3F',
borderTopColor: 'transparent'
},
activeTintColor: '#E6B056',
}}
>
<Tab.Screen
name="ProfileScreen"
ponent={ProfileScreen}
options={{
tabBarIcon: ({color}) => (
<Ionicons name="person" size={32} color={color} />
)
}}
/>
<Tab.Screen
name="MatchScreen"
ponent={MatchScreen}
options={{
tabBarIcon: ({color}) => (
<Image
style={{ width: 38, height: 38 }}
source={require('../images/Icons/ico-menu-busca-evas.png')}
/>
)
}}
/>
<Tab.Screen
name="CheckIn"
ponent={CheckIn}
options={{
tabBarIcon: ({color}) => (
<FontAwesome5 name="map-marker" size={32} color={color} />
)
}}
/>
<Tab.Screen name="ChatScreen"
ponent={ChatScreen}
options={{
tabBarIcon: ({color}) => (
<Ionicons name="chatbubbles" size={32} color={color} />
)
}}
/>
</Tab.Navigator>
)
}
I'm using React navigation to change screens with the bottom tab navigations, but when I try to use a custom SVG I have many troubles and using an image to show as an icon the color obviously doesn't change, how can I use an SVG file that can recognize the color im passing to change when I'm on the page?
function MyTabs() {
return(
<Tab.Navigator
tabBarOptions={{
showLabel: false,
style:{
backgroundColor:'#313A3F',
borderTopColor: 'transparent'
},
activeTintColor: '#E6B056',
}}
>
<Tab.Screen
name="ProfileScreen"
ponent={ProfileScreen}
options={{
tabBarIcon: ({color}) => (
<Ionicons name="person" size={32} color={color} />
)
}}
/>
<Tab.Screen
name="MatchScreen"
ponent={MatchScreen}
options={{
tabBarIcon: ({color}) => (
<Image
style={{ width: 38, height: 38 }}
source={require('../images/Icons/ico-menu-busca-evas.png')}
/>
)
}}
/>
<Tab.Screen
name="CheckIn"
ponent={CheckIn}
options={{
tabBarIcon: ({color}) => (
<FontAwesome5 name="map-marker" size={32} color={color} />
)
}}
/>
<Tab.Screen name="ChatScreen"
ponent={ChatScreen}
options={{
tabBarIcon: ({color}) => (
<Ionicons name="chatbubbles" size={32} color={color} />
)
}}
/>
</Tab.Navigator>
)
}
Share
Improve this question
asked Jul 21, 2021 at 20:18
Renan Tiberio OlovicsRenan Tiberio Olovics
651 silver badge4 bronze badges
1
- "@react-navigation/bottom-tabs": "^5.11.11", "@react-navigation/native": "^5.9.4", "@react-navigation/stack": "^5.14.5", "expo": "^41.0.0", "react-native-svg": "^12.1.1", "react-native-svg-uri": "^1.2.3", "@expo/vector-icons": "^12.0.0", – Renan Tiberio Olovics Commented Jul 21, 2021 at 20:27
2 Answers
Reset to default 2I have fixed this issue using:
import Svg, { G, Path } from 'react-native-svg';
then using the original svg passing props for color and size.
The accepted answer from @Renan works, I just wanted to share the full code sample. So, like he said, first add this import...
import Svg, { G, Path } from 'react-native-svg';
after that, use it like this in your code...
<Svg
width={size}
height={size}
viewBox='0 0 24 24'
fillRule='evenodd'
clipRule='evenodd'
strokeLinejoin='round'
strokeMiterlimit={2}
>
<G transform='matrix(1,0,0,1,-2.99997,-1.5)'>
<Path
d='M13.003,14C13.553,14 14,13.544 14,13.005L14,4.995C13.997,4.449 13.549,4.002 13.003,4L6.997,4C6.447,4 6,4.456 6,4.995L6,13.005C6.003,13.551 6.451,13.998 6.997,14L13.003,14ZM13.003,23C13.553,23 14,22.562 14,21.997L14,17.003C14,16.449 13.547,16 13.003,16L6.997,16C6.996,16 6.994,16 6.993,16C6.448,16 6,16.448 6,16.993C6,16.996 6,17 6,17.003L6,21.997C6,22.551 6.453,23 6.997,23L13.003,23ZM23.003,23C23.553,23 24,22.555 24,22.004L24,12.996C23.998,12.45 23.549,12.002 23.003,12L16.997,12C16.997,12 16.996,12 16.996,12C16.45,12 16,12.45 16,12.996L16,22.004C16.002,22.55 16.451,22.998 16.997,23L23.003,23ZM16,9.01C16,9.556 16.453,10 16.997,10L23.003,10C23.553,10 24,9.549 24,9.01L24,4.99C23.996,4.446 23.547,4.001 23.003,4L16.997,4C16.453,4.001 16.005,4.446 16,4.99L16,9.01Z'
fill={color}
/>
</G>
</Svg>
I'm using React navigation to change screens with the bottom tab navigations, but when I try to use a custom SVG I have many troubles and using an image to show as an icon the color obviously doesn't change, how can I use an SVG file that can recognize the color im passing to change when I'm on the page?
function MyTabs() {
return(
<Tab.Navigator
tabBarOptions={{
showLabel: false,
style:{
backgroundColor:'#313A3F',
borderTopColor: 'transparent'
},
activeTintColor: '#E6B056',
}}
>
<Tab.Screen
name="ProfileScreen"
ponent={ProfileScreen}
options={{
tabBarIcon: ({color}) => (
<Ionicons name="person" size={32} color={color} />
)
}}
/>
<Tab.Screen
name="MatchScreen"
ponent={MatchScreen}
options={{
tabBarIcon: ({color}) => (
<Image
style={{ width: 38, height: 38 }}
source={require('../images/Icons/ico-menu-busca-evas.png')}
/>
)
}}
/>
<Tab.Screen
name="CheckIn"
ponent={CheckIn}
options={{
tabBarIcon: ({color}) => (
<FontAwesome5 name="map-marker" size={32} color={color} />
)
}}
/>
<Tab.Screen name="ChatScreen"
ponent={ChatScreen}
options={{
tabBarIcon: ({color}) => (
<Ionicons name="chatbubbles" size={32} color={color} />
)
}}
/>
</Tab.Navigator>
)
}
I'm using React navigation to change screens with the bottom tab navigations, but when I try to use a custom SVG I have many troubles and using an image to show as an icon the color obviously doesn't change, how can I use an SVG file that can recognize the color im passing to change when I'm on the page?
function MyTabs() {
return(
<Tab.Navigator
tabBarOptions={{
showLabel: false,
style:{
backgroundColor:'#313A3F',
borderTopColor: 'transparent'
},
activeTintColor: '#E6B056',
}}
>
<Tab.Screen
name="ProfileScreen"
ponent={ProfileScreen}
options={{
tabBarIcon: ({color}) => (
<Ionicons name="person" size={32} color={color} />
)
}}
/>
<Tab.Screen
name="MatchScreen"
ponent={MatchScreen}
options={{
tabBarIcon: ({color}) => (
<Image
style={{ width: 38, height: 38 }}
source={require('../images/Icons/ico-menu-busca-evas.png')}
/>
)
}}
/>
<Tab.Screen
name="CheckIn"
ponent={CheckIn}
options={{
tabBarIcon: ({color}) => (
<FontAwesome5 name="map-marker" size={32} color={color} />
)
}}
/>
<Tab.Screen name="ChatScreen"
ponent={ChatScreen}
options={{
tabBarIcon: ({color}) => (
<Ionicons name="chatbubbles" size={32} color={color} />
)
}}
/>
</Tab.Navigator>
)
}
Share
Improve this question
asked Jul 21, 2021 at 20:18
Renan Tiberio OlovicsRenan Tiberio Olovics
651 silver badge4 bronze badges
1
- "@react-navigation/bottom-tabs": "^5.11.11", "@react-navigation/native": "^5.9.4", "@react-navigation/stack": "^5.14.5", "expo": "^41.0.0", "react-native-svg": "^12.1.1", "react-native-svg-uri": "^1.2.3", "@expo/vector-icons": "^12.0.0", – Renan Tiberio Olovics Commented Jul 21, 2021 at 20:27
2 Answers
Reset to default 2I have fixed this issue using:
import Svg, { G, Path } from 'react-native-svg';
then using the original svg passing props for color and size.
The accepted answer from @Renan works, I just wanted to share the full code sample. So, like he said, first add this import...
import Svg, { G, Path } from 'react-native-svg';
after that, use it like this in your code...
<Svg
width={size}
height={size}
viewBox='0 0 24 24'
fillRule='evenodd'
clipRule='evenodd'
strokeLinejoin='round'
strokeMiterlimit={2}
>
<G transform='matrix(1,0,0,1,-2.99997,-1.5)'>
<Path
d='M13.003,14C13.553,14 14,13.544 14,13.005L14,4.995C13.997,4.449 13.549,4.002 13.003,4L6.997,4C6.447,4 6,4.456 6,4.995L6,13.005C6.003,13.551 6.451,13.998 6.997,14L13.003,14ZM13.003,23C13.553,23 14,22.562 14,21.997L14,17.003C14,16.449 13.547,16 13.003,16L6.997,16C6.996,16 6.994,16 6.993,16C6.448,16 6,16.448 6,16.993C6,16.996 6,17 6,17.003L6,21.997C6,22.551 6.453,23 6.997,23L13.003,23ZM23.003,23C23.553,23 24,22.555 24,22.004L24,12.996C23.998,12.45 23.549,12.002 23.003,12L16.997,12C16.997,12 16.996,12 16.996,12C16.45,12 16,12.45 16,12.996L16,22.004C16.002,22.55 16.451,22.998 16.997,23L23.003,23ZM16,9.01C16,9.556 16.453,10 16.997,10L23.003,10C23.553,10 24,9.549 24,9.01L24,4.99C23.996,4.446 23.547,4.001 23.003,4L16.997,4C16.453,4.001 16.005,4.446 16,4.99L16,9.01Z'
fill={color}
/>
</G>
</Svg>
本文标签: javascriptReact navigation (Tab Navigator) with custom SVGIconsStack Overflow
版权声明:本文标题:javascript - React navigation (Tab Navigator) with custom SVGIcons - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745651416a2161340.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论