Skip to content

Commit

Permalink
fix: android rn screen crash (#5062)
Browse files Browse the repository at this point in the history
* Don't restore state in main activity

* Add explanatory comment and HACKS.md entry

* Update changelog
  • Loading branch information
brainbicycle committed Jun 30, 2021
1 parent 55e5138 commit 62b1bbe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ upcoming:
- Implement share button for articles - katsiaryna alshannikava, mounir
- Connect auction results for you to metaphysics endpoint - yauheni
- Fix opening artist page after passing new onboarding on ios - dzmitry
- Fix crash when opening app from background on android - brian
- Change error handling middleware & include optionalField graphql directive to home screen - ole

releases:
Expand Down
13 changes: 13 additions & 0 deletions HACKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,16 @@ Once we work on [CX-1421](https://artsyproduct.atlassian.net/browse/CX-1421?atlO
Basically these patches remove the podspecs of these two deps. They confuse and break ios, and we don't use them there yet anyway.

Once we start working on replacing the native analytics with TS ones, then we remove these two patches too.

# `react-native-screens` fragment crash on open from background on Android

#### When can we remove this:

Once https://github.com/software-mansion/react-native-screens/issues/17 is solved or we use another library for screen management.

#### Explanation/Context:

There is a known issue in react-native-screens that causes the app to crash on restoring from background. The react-native-screens team recommends the following workaround to be
added to the MainActivity class on Android https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067.

This has the UX downside of not allowing state restore from background but this is an unsolved problem for RN apps.
6 changes: 5 additions & 1 deletion android/app/src/main/java/net/artsy/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ private boolean isTablet() {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Following line is required to prevent a crash
// See HACKS.md for more context
// https://github.com/software-mansion/react-native-screens/issues/17
super.onCreate(null);

if (!isTablet()) {
// prevent screen rotation on phones
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Expand Down

0 comments on commit 62b1bbe

Please sign in to comment.