Skip to content

Commit 889acc3

Browse files
committed
fix: update docs for RN gradient closes #194
1 parent 9e01e72 commit 889acc3

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

packages/mobile/README.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,34 @@ const children = ({ remainingTime }) => (
177177

178178
### Add gradient
179179

180-
Define the SVG gradient outside the Timer component and pass the gradient ID to the Timer component as a single color:
180+
Since the gradient definition and the usage of it has to be placed under the same SVG element we should use the `useCountdown` hook and build the countdown component ourself. Check [this demo](https://snack.expo.dev/@dimitrov/react-native-countdown-circle-timer-gradient?platform=ios) to see how it works.
181181

182182
```jsx
183-
<Svg>
184-
<Defs>
185-
<LinearGradient id="your-unique-id" x1="1" y1="0" x2="0" y2="0">
186-
<Stop offset="5%" stopColor="gold" />
187-
<Stop offset="95%" stopColor="red" />
188-
</LinearGradient>
189-
</Defs>
190-
</Svg>
191-
<CountdownCircleTimer colors="url(#your-unique-id)">
192-
{({ remainingTime }) => <Text>{remainingTime}</Text>}
193-
</CountdownCircleTimer>
183+
const {
184+
...
185+
} = useCountdown({ isPlaying: true, duration, colors: 'url(#your-unique-id)' })
186+
187+
<Svg width={size} height={size}>
188+
<Defs>
189+
<LinearGradient id="your-unique-id" x1="1" y1="0" x2="0" y2="0">
190+
<Stop offset="5%" stopColor="gold"/>
191+
<Stop offset="95%" stopColor="red"/>
192+
</LinearGradient>
193+
</Defs>
194+
<Path
195+
d={path}
196+
fill="none"
197+
stroke="#d9d9d9"
198+
strokeWidth={strokeWidth}
199+
/>
200+
<Path
201+
d={path}
202+
fill="none"
203+
stroke={stroke}
204+
strokeLinecap="butt"
205+
strokeWidth={strokeWidth}
206+
strokeDasharray={pathLength}
207+
strokeDashoffset={strokeDashoffset}
208+
/>
209+
</Svg>
194210
```

0 commit comments

Comments
 (0)