|
| 1 | +import React, {useState} from 'react'; |
| 2 | +import {View, Button, Text} from 'react-native'; |
| 3 | +import {Svg, Path} from 'react-native-svg'; |
| 4 | + |
| 5 | +const PathChangingFillFromValueToUndefined = () => { |
| 6 | + const [fill, setFill] = useState<string | undefined>(undefined); |
| 7 | + |
| 8 | + const changeFill = () => { |
| 9 | + setFill(prevFill => (prevFill ? undefined : 'red')); |
| 10 | + }; |
| 11 | + |
| 12 | + return ( |
| 13 | + <View |
| 14 | + style={{ |
| 15 | + width: 200, |
| 16 | + margin: 50, |
| 17 | + aspectRatio: 1, |
| 18 | + alignItems: 'center', |
| 19 | + justifyContent: 'center', |
| 20 | + }}> |
| 21 | + <Text>Path which on a button click sets or resets fill to undefined</Text> |
| 22 | + <Button onPress={changeFill} title="Change fill" /> |
| 23 | + <Svg height="100" width="100"> |
| 24 | + <Path |
| 25 | + d="M25 10 L98 65 L70 25 L16 77 L11 30 L0 4 L90 50 L50 10 L11 22 L77 95 L20 25" |
| 26 | + fill={fill} |
| 27 | + /> |
| 28 | + </Svg> |
| 29 | + </View> |
| 30 | + ); |
| 31 | +}; |
| 32 | + |
| 33 | +const PathChangingFillFromValueToFillNone = () => { |
| 34 | + const [fill, setFill] = useState<string | 'none'>('none'); |
| 35 | + |
| 36 | + const changeFill = () => { |
| 37 | + setFill(prevFill => (prevFill !== 'none' ? 'none' : 'red')); |
| 38 | + }; |
| 39 | + |
| 40 | + return ( |
| 41 | + <View |
| 42 | + style={{ |
| 43 | + width: 200, |
| 44 | + margin: 50, |
| 45 | + aspectRatio: 1, |
| 46 | + alignItems: 'center', |
| 47 | + justifyContent: 'center', |
| 48 | + }}> |
| 49 | + <Text> |
| 50 | + Path which on a button click sets or resets fill to none value |
| 51 | + </Text> |
| 52 | + <Button onPress={changeFill} title="Change fill" /> |
| 53 | + <Svg height="100" width="100"> |
| 54 | + <Path |
| 55 | + d="M25 10 L98 65 L70 25 L16 77 L11 30 L0 4 L90 50 L50 10 L11 22 L77 95 L20 25" |
| 56 | + fill={fill} |
| 57 | + /> |
| 58 | + </Svg> |
| 59 | + </View> |
| 60 | + ); |
| 61 | +}; |
| 62 | + |
| 63 | +export default function App() { |
| 64 | + return ( |
| 65 | + <View style={{justifyContent: 'center', alignItems: 'center', flex: 1}}> |
| 66 | + <PathChangingFillFromValueToUndefined /> |
| 67 | + <PathChangingFillFromValueToFillNone /> |
| 68 | + </View> |
| 69 | + ); |
| 70 | +} |
0 commit comments