-
-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: screen rewritten as functional component #2111
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, great job 🎉 I've got few remarks and questions we need to answer before we can merge these changes.
The rest of changes look very promising, but I would ask you to test them within our TestsExample
application in following scenarios:
- using native-stack v5 (
createNativeStackNavigator
imported fromreact-native-screens
- using native-stack v6 (
createNativeStackNavigator
imported from@react-navigation/native-stack
Please be aware of prop naming differences between v5 & v6.
We need to check few selected tests (1072, 1069 and some with reanimated should be amongst them) whether we don't have any undesired behaviour in downstream projects.
src/components/Screen.tsx
Outdated
const closing = new Animated.Value(0); | ||
const progress = new Animated.Value(0); | ||
const goingForward = new Animated.Value(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are moved from state to being recreated on every rerender. Is that intentional? Do we expect any issues here? @WoLewicki asking for some insights here. I'm not really familiar with semantics of Animated
values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe leveraging the useRef hook to store the values would be a good idea? What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was also my initial thought & I think we should go for this.
In any case I would like to hear from someone who might now some internals (already tagged).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I can see that in the example they use useRef
for it: https://reactnative.dev/docs/animated#example. If it works correctly then it seems like the way to go. I can also see that a similar concept is used in react-navigation
: https://github.com/react-navigation/react-navigation/blob/d0abdee67f5db8cf39112af535846ffededfb21d/packages/react-native-tab-view/src/useAnimatedValue.tsx#L4
setNativeProps(props: ScreenProps): void { | ||
this.ref?.setNativeProps(props); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before we can remove this method as unused, we need to make sure no one actually uses it 😅 We need to:
- check
react-navigation
code for any usages of these, - as this seems like method that could be utilised by
react-native-reanimated
- we need to also look for usages there (also see ourReanimatedScreenProvider
) - it would be best to consult withreanimated
team, - thinking now, I would rather leave this method exposed in this PR 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is this intentional & you are utilising this method defined on innerRef
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe Animated
still uses setNativeProps
under the hood so I'd leave it. After quick talk with @piaskowyk, react-native-reanimated
is not utilizing it, but still we would want it for Animated
. @alduzy did you maybe check examples with Animated
to see if they work when this code is removed? Would be also good to check with both useNativeDriver
set to false
and true
and in TestsExample
and FabricTestsExample
.
|
||
setRef = (ref: React.ElementRef<typeof View> | null): void => { | ||
this.ref = ref; | ||
this.props.onComponentRef?.(ref); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see some comment why do we resign from calling this callback here (onComponentRef)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an oversight, brought it back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I answered some questions and left my own. Please answer them. Good job overall 🎉
export const InnerScreen = React.forwardRef<View, ScreenProps>( | ||
function InnerScreen(props, ref) { | ||
const innerRef = React.useRef<ViewConfig | null>(null); | ||
React.useImperativeHandle(ref, () => innerRef.current!, []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this line for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is intended to replace removed code mentioned above:
setNativeProps(props: ScreenProps): void { this.ref?.setNativeProps(props); }
However I am not sure wether it is correctly implemented
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! If it has been tested with both react-native-reanimated
and Animated
and on both new and old architecture, then we can merge it 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on the above comment from @WoLewicki
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🥳
…2111) ## Description This PR intents to change Screen component into a functional component.
Description
This PR intents to change Screen component into a functional component.