Browse Source

Add toolbar toggle, not sure if animation is working

Jason Skuby 8 years ago
parent
commit
ab595a4b79

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java View File

382
     public void toggleTabs(ReadableMap params) {
382
     public void toggleTabs(ReadableMap params) {
383
         return;
383
         return;
384
     }
384
     }
385
+
386
+    public void toggleNavigationBar(ReadableMap params) {
387
+        if (mToolbar == null) {
388
+            return;
389
+        }
390
+
391
+        boolean hide = params.getBoolean(KEY_HIDDEN);
392
+        boolean animated = params.getBoolean(KEY_ANIMATED);
393
+        if (hide) {
394
+            mToolbar.hideToolbar(animated);
395
+        } else {
396
+            mToolbar.showToolbar(animated);
397
+        }
398
+    }
385
 }
399
 }

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/modules/RctActivityModule.java View File

148
         });
148
         });
149
     }
149
     }
150
 
150
 
151
+    @ReactMethod
152
+    public void toggleNavigationBar(final ReadableMap params) {
153
+        final BaseReactActivity context = ContextProvider.getActivityContext();
154
+        if (context == null || context.isFinishing()) {
155
+            return;
156
+        }
157
+        context.runOnUiThread(new Runnable() {
158
+            @Override
159
+            public void run() {
160
+                context.toggleNavigationBar(params);
161
+            }
162
+        });
163
+    }
164
+
151
     @ReactMethod
165
     @ReactMethod
152
     public void toggleNavigatorTabs(final ReadableMap params) {
166
     public void toggleNavigatorTabs(final ReadableMap params) {
153
         final BaseReactActivity context = ContextProvider.getActivityContext();
167
         final BaseReactActivity context = ContextProvider.getActivityContext();

+ 15
- 3
android/app/src/main/java/com/reactnativenavigation/views/RnnToolBar.java View File

40
  */
40
  */
41
 public class RnnToolBar extends Toolbar {
41
 public class RnnToolBar extends Toolbar {
42
 
42
 
43
+    private static final int ANIMATE_DURATION = 180;
44
+
43
     private List<Screen> mScreens;
45
     private List<Screen> mScreens;
44
     private AsyncTask mSetupToolbarTask;
46
     private AsyncTask mSetupToolbarTask;
45
     private Drawable mBackground;
47
     private Drawable mBackground;
81
         } else {
83
         } else {
82
             resetTitleTextColor();
84
             resetTitleTextColor();
83
         }
85
         }
84
-        
86
+
85
         if (screen.toolBarHidden != null && screen.toolBarHidden) {
87
         if (screen.toolBarHidden != null && screen.toolBarHidden) {
86
             hideToolbar();
88
             hideToolbar();
87
         } else {
89
         } else {
112
         }
114
         }
113
     }
115
     }
114
 
116
 
115
-    private void showToolbar() {
117
+    public void showToolbar(boolean animated) {
116
         ActionBar actionBar = ((AppCompatActivity) getContext()).getSupportActionBar();
118
         ActionBar actionBar = ((AppCompatActivity) getContext()).getSupportActionBar();
117
         if (actionBar != null) {
119
         if (actionBar != null) {
120
+            actionBar.setShowHideAnimationEnabled(animated);
118
             actionBar.show();
121
             actionBar.show();
119
         }
122
         }
120
     }
123
     }
121
 
124
 
122
-    private void hideToolbar() {
125
+    public void hideToolbar(boolean animated) {
123
         ActionBar actionBar = ((AppCompatActivity) getContext()).getSupportActionBar();
126
         ActionBar actionBar = ((AppCompatActivity) getContext()).getSupportActionBar();
124
         if (actionBar != null) {
127
         if (actionBar != null) {
128
+            actionBar.setShowHideAnimationEnabled(animated);
125
             actionBar.hide();
129
             actionBar.hide();
126
         }
130
         }
127
     }
131
     }
128
 
132
 
133
+    private void showToolbar() {
134
+        showToolbar(false);
135
+    }
136
+
137
+    private void hideToolbar() {
138
+        hideToolbar(false);
139
+    }
140
+
129
     @SuppressWarnings({"ConstantConditions"})
141
     @SuppressWarnings({"ConstantConditions"})
130
     public void showBackButton(Screen screen) {
142
     public void showBackButton(Screen screen) {
131
         ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
143
         ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();

+ 10
- 2
src/platformSpecific.android.js View File

101
   });
101
   });
102
 }
102
 }
103
 
103
 
104
+function navigatorToggleNavBar(navigator, params) {
105
+  RctActivity.toggleNavigationBar({
106
+    hidden: params.to === 'hidden',
107
+    animated: !(params.animated === false)
108
+  });
109
+}
110
+
104
 function navigatorToggleTabs(navigator, params) {
111
 function navigatorToggleTabs(navigator, params) {
105
   RctActivity.toggleNavigatorTabs({
112
   RctActivity.toggleNavigatorTabs({
106
-    hidden: params.to == 'hidden',
113
+    hidden: params.to === 'hidden',
107
     animated: !(params.animated === false)
114
     animated: !(params.animated === false)
108
   });
115
   });
109
 }
116
 }
167
   navigatorSetTabBadge,
174
   navigatorSetTabBadge,
168
   navigatorSetTitle,
175
   navigatorSetTitle,
169
   navigatorSwitchToTab,
176
   navigatorSwitchToTab,
170
-  navigatorToggleTabs
177
+  navigatorToggleTabs,
178
+  navigatorToggleNavBar
171
 }
179
 }