Last active
June 4, 2025 10:34
-
-
Save lunaleaps/eac391bf3fe4c85953cefeb74031bab0 to your computer and use it in GitHub Desktop.
Rendering many tiles without startTransition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as React from 'react'; | |
| import {SafeAreaView, Text, View, ActivityIndicator} from 'react-native'; | |
| import Slider from '@react-native-community/slider'; | |
| function SliderHeader({ | |
| value, | |
| onValueChange, | |
| }: { | |
| value: number; | |
| onValueChange: (value: number) => void; | |
| }) { | |
| const [isPending, startTransition] = React.useTransition(); | |
| return ( | |
| <> | |
| <View | |
| style={{ | |
| flexDirection: 'row', | |
| justifyContent: 'space-between', | |
| paddingHorizontal: 8, | |
| }}> | |
| <Text style={{textAlign: 'center'}}> | |
| Render <Text style={{fontWeight: '500'}}>{value}</Text> Tiles{' '} | |
| </Text> | |
| <ActivityIndicator animating={isPending} /> | |
| </View> | |
| <Slider | |
| value={1} | |
| minimumValue={1} | |
| maximumValue={1000} | |
| step={1} | |
| onValueChange={newValue => { | |
| // Do not mark this update as a transition | |
| onValueChange(newValue); | |
| }} | |
| /> | |
| </> | |
| ); | |
| } | |
| export default function ManyTiles() { | |
| const views = []; | |
| const size = 14; | |
| const [value, setValue] = React.useState(1); | |
| for (let i = 0; i < value; ++i) { | |
| const view = ( | |
| <View | |
| key={i} | |
| style={{ | |
| width: size, | |
| height: size, | |
| borderWidth: 0.5, | |
| backgroundColor: 'red', | |
| }} | |
| /> | |
| ); | |
| views.push(view); | |
| } | |
| return ( | |
| <SafeAreaView style={{backgroundColor: 'white'}}> | |
| <SliderHeader onValueChange={setValue} value={value} /> | |
| <View | |
| style={{ | |
| flexDirection: 'row', | |
| flex: 1, | |
| flexWrap: 'wrap', | |
| }}> | |
| {views} | |
| </View> | |
| </SafeAreaView> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great work
I'll need more clearity on it please am a bit confuse on the workflow.