瀏覽代碼

Unmount custom TitleBar buttons

Guy Carmeli 7 年之前
父節點
當前提交
db69a30a35

+ 0
- 1
android/app/src/main/java/com/reactnativenavigation/screens/CollapsingViewPagerScreen.java 查看文件

111
                 ((CollapsingContentView) contentView).destroy();
111
                 ((CollapsingContentView) contentView).destroy();
112
             }
112
             }
113
         }
113
         }
114
-        topBar.destroy();
115
     }
114
     }
116
 
115
 
117
     protected ContentView getCurrentPage() {
116
     protected ContentView getCurrentPage() {

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java 查看文件

367
         unmountReactView();
367
         unmountReactView();
368
         EventBus.instance.unregister(this);
368
         EventBus.instance.unregister(this);
369
         sharedElements.destroy();
369
         sharedElements.destroy();
370
+        topBar.destroy();
370
     }
371
     }
371
 }
372
 }

+ 12
- 0
android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java 查看文件

324
             leftButton.updateNavigatorEventId(screenParams.getNavigatorEventId());
324
             leftButton.updateNavigatorEventId(screenParams.getNavigatorEventId());
325
         }
325
         }
326
     }
326
     }
327
+
328
+    public void destroy() {
329
+        unmountCustomButtons();
330
+    }
331
+
332
+    private void unmountCustomButtons() {
333
+        for (int i = 0; i < actionMenuView.getChildCount(); i++) {
334
+            if (actionMenuView.getChildAt(i) instanceof TitleBarButtonComponent) {
335
+                ((ContentView) actionMenuView.getChildAt(i)).unmountReactView();
336
+            }
337
+        }
338
+    }
327
 }
339
 }

+ 0
- 25
android/app/src/main/java/com/reactnativenavigation/views/TitleBarCustomComponentButton.java 查看文件

1
-package com.reactnativenavigation.views;
2
-
3
-import android.content.Context;
4
-import android.support.annotation.Nullable;
5
-import android.view.Menu;
6
-import android.view.MenuItem;
7
-import android.view.View;
8
-
9
-import com.reactnativenavigation.params.NavigationParams;
10
-import com.reactnativenavigation.params.TitleBarButtonParams;
11
-
12
-class TitleBarCustomComponentButton extends TitleBarButton {
13
-    TitleBarCustomComponentButton(Menu menu, View parent, TitleBarButtonParams buttonParams, @Nullable String navigatorEventId) {
14
-        super(menu, parent, buttonParams, navigatorEventId);
15
-    }
16
-
17
-    @Override
18
-    MenuItem addToMenu(int index) {
19
-        throw new RuntimeException("Can't add custom component to menu");
20
-    }
21
-
22
-    View createView(Context context) {
23
-        return new ContentView(context, buttonParams.componentName, NavigationParams.EMPTY, buttonParams.componentProps);
24
-    }
25
-}

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java 查看文件

219
         if (reactView != null) {
219
         if (reactView != null) {
220
             reactView.unmountReactView();
220
             reactView.unmountReactView();
221
         }
221
         }
222
+        titleBar.destroy();
222
     }
223
     }
223
 
224
 
224
     public void onViewPagerScreenChanged(BaseScreenParams screenParams) {
225
     public void onViewPagerScreenChanged(BaseScreenParams screenParams) {