Skip to content

Commit

Permalink
Skip saving/restoring state for unmounted fragments. (#313)
Browse files Browse the repository at this point in the history
We currently cannot take any adventage of saving and restoring fragment state because view hierarchy of the unmounted fragment is retained by RN core anyways. Skipping sabe/restore will allow us to avoid unnecessary serializiation/deserialization of the view hierarchy but will also help circumvent some bugs which comes from the side effects of restoring. One of the bugs have been reported in #162 and in that particular case restoring result in InputText change event being triggered with stale value. This was happening in the situation when we were going back to a screen with InputText component.
  • Loading branch information
kmagiera committed Feb 6, 2020
1 parent 10a0bad commit ed997ef
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions android/src/main/java/com/swmansion/rnscreens/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.content.Context;
import android.graphics.Paint;
import android.os.Parcelable;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
Expand Down Expand Up @@ -68,6 +70,18 @@ public Screen(ReactContext context) {
setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_APPLICATION));
}

@Override
protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) {
// do nothing, react native will keep the view hierarchy so no need to serialize/deserialize
// view's states. The side effect of restoring is that TextInput components would trigger set-text
// events which may confuse text input handling.
}

@Override
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
// ignore restoring instance state too as we are not saving anything anyways.
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
if (changed) {
Expand Down

0 comments on commit ed997ef

Please sign in to comment.