|
4 | 4 | import android.content.Context;
|
5 | 5 | import android.os.Bundle;
|
6 | 6 | import android.view.MotionEvent;
|
| 7 | +import android.view.View; |
| 8 | +import android.view.ViewGroup; |
7 | 9 |
|
8 | 10 | import com.facebook.react.ReactInstanceManager;
|
9 | 11 | import com.facebook.react.ReactRootView;
|
|
20 | 22 |
|
21 | 23 | import androidx.annotation.RestrictTo;
|
22 | 24 |
|
| 25 | +import java.util.ArrayList; |
| 26 | +import java.util.List; |
| 27 | + |
23 | 28 | @SuppressLint("ViewConstructor")
|
24 | 29 | public class ReactView extends ReactRootView implements IReactView, Renderable {
|
25 | 30 |
|
@@ -64,7 +69,26 @@ public ReactView asView() {
|
64 | 69 |
|
65 | 70 | @Override
|
66 | 71 | public void destroy() {
|
| 72 | + // get current children and id |
| 73 | + ViewGroup rootViewGroup = getRootViewGroup(); |
| 74 | + int childCount = rootViewGroup.getChildCount(); |
| 75 | + int id = rootViewGroup.getId(); |
| 76 | + List<View> children = new ArrayList<>(); |
| 77 | + for (int i = 0; i < childCount; i++) { |
| 78 | + children.add(rootViewGroup.getChildAt(i)); |
| 79 | + } |
| 80 | + |
| 81 | + // unmount will remove all children and reset the id |
| 82 | + // which cause the onDropViewInstance not called. |
67 | 83 | unmountReactApplication();
|
| 84 | + |
| 85 | + // restore removed children and revert the id |
| 86 | + // then the onDropViewInstance will be called. |
| 87 | + // and NativeViewHierarchyManager will help to remove these children later. |
| 88 | + for (int i = 0; i < children.size(); i++) { |
| 89 | + rootViewGroup.addView(children.get(i)); |
| 90 | + } |
| 91 | + rootViewGroup.setId(id); |
68 | 92 | }
|
69 | 93 |
|
70 | 94 | public void sendComponentWillStart(ComponentType type) {
|
|
0 commit comments