mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-06-13 09:35:07 +08:00
Skip saving/restoring state for unmounted fragments. (#313)
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.
This commit is contained in:
committed by
GitHub
parent
10a0badee2
commit
ed997ef4ec
@@ -2,6 +2,8 @@ package com.swmansion.rnscreens;
|
||||
|
||||
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;
|
||||
@@ -68,6 +70,18 @@ public class Screen extends ViewGroup {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user