-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow preload using activityState (#2389)
## Description This PR is a rewrite of #2278 using already existing `activityState` -> to avoid introducing redundant prop. Connected PR to react-navigation: react-navigation/react-navigation#12189 ## Test code and steps to reproduce You can play with the preload feature in `TestPreload.tsx` To test assertion of activityState progress go to `TestActivityStateProgression.tsx` - keep in mind that if the Screen has `isNativeStack` it will just run JS validation, remove the prop to test native checks. ## Checklist - [ ] Included code example that can be used to test this change - [ ] Updated TS types - [x] Updated documentation: <!-- For adding new props to native-stack --> - [x] https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md - [ ] https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md - [ ] https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx - [ ] https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx - [ ] Ensured that CI passes --------- Co-authored-by: Kacper Kafara <[email protected]>
- Loading branch information
1 parent
6154c2b
commit cce7d78
Showing
11 changed files
with
486 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as React from 'react'; | ||
import { View, Text, Button } from 'react-native'; | ||
import { Screen, ScreenStack } from '../../../src'; | ||
|
||
function HomeScreen({ | ||
setActivityState, | ||
}: { | ||
setActivityState: (state: 0 | 1 | 2) => void; | ||
}) { | ||
console.log('Render home'); | ||
return ( | ||
<View | ||
style={{ | ||
flex: 1, | ||
gap: 8, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}}> | ||
<Text>Home!</Text> | ||
<Button | ||
title="Set Activity State to 2" | ||
onPress={() => setActivityState(2)} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
function ProfileScreen({ | ||
setActivityState, | ||
}: { | ||
setActivityState: (state: 0 | 1 | 2) => void; | ||
}) { | ||
console.log('Render profile'); | ||
return ( | ||
<View | ||
style={{ | ||
flex: 1, | ||
gap: 8, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}}> | ||
<Text>Profile!</Text> | ||
<Button | ||
title="Set Activity State to 0" | ||
onPress={() => setActivityState(0)} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
const App = () => { | ||
const [activityState, setActivityState] = React.useState<0 | 1 | 2>(0); | ||
console.log('activityState', activityState); | ||
|
||
/** | ||
* Remove isNativeStack if you want to test native checks | ||
*/ | ||
return ( | ||
<ScreenStack style={{ flex: 1 }}> | ||
<Screen activityState={2} isNativeStack> | ||
<HomeScreen setActivityState={setActivityState} /> | ||
</Screen> | ||
<Screen activityState={activityState} isNativeStack> | ||
<ProfileScreen setActivityState={setActivityState} /> | ||
</Screen> | ||
</ScreenStack> | ||
); | ||
}; | ||
export default App; |
Oops, something went wrong.