Skip to content
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

fix: wrap Screen with ScreenContext #1539

Merged
merged 3 commits into from
Jul 25, 2022

Conversation

kacperkapusciak
Copy link
Member

@kacperkapusciak kacperkapusciak commented Jul 20, 2022

Description

This PR exposes a Screen which is prewrapped with ScreenContext. Previous Screen implementation is internally renamed InnerScreen and should have no effect on the outside use of the library.

This change is necessary to use useReanimatedTransitionProgress feature without additional setup within react-navigation repo.

Discussed in detail in react-navigation/react-navigation#10585

Closes react-navigation/react-navigation#10585

Test code and steps to reproduce

Test1539.tsx in TestsExample project.

Checklist

  • Included code example that can be used to test this change
  • Ensured that CI passes

Comment on lines +414 to +421
class Screen extends React.Component<ScreenProps> {
static contextType = ScreenContext;

render() {
const ScreenWrapper = this.context || InnerScreen;
return <ScreenWrapper {...this.props} />;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could use a functional syntax here eg.:

const Screen = React.forwardRef<any, any>(function Screen(props, ref) {
  const TurboScreen = React.useContext(ScreenContext);
  const ScreenWrapper = TurboScreen || InnerScreen;
  return <ScreenWrapper {...props} ref={ref} />;
});

which I think here is more complicated than the class-based.

Copy link
Member

@WoLewicki WoLewicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@kkafar kkafar merged commit 67d1fd1 into main Jul 25, 2022
@kkafar kkafar deleted the @kacperkapusciak/wrap-screen-with-screen-context branch July 25, 2022 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants