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,4 +382,18 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
382 382
     public void toggleTabs(ReadableMap params) {
383 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,6 +148,20 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
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 165
     @ReactMethod
152 166
     public void toggleNavigatorTabs(final ReadableMap params) {
153 167
         final BaseReactActivity context = ContextProvider.getActivityContext();

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

@@ -40,6 +40,8 @@ import java.util.Map;
40 40
  */
41 41
 public class RnnToolBar extends Toolbar {
42 42
 
43
+    private static final int ANIMATE_DURATION = 180;
44
+
43 45
     private List<Screen> mScreens;
44 46
     private AsyncTask mSetupToolbarTask;
45 47
     private Drawable mBackground;
@@ -81,7 +83,7 @@ public class RnnToolBar extends Toolbar {
81 83
         } else {
82 84
             resetTitleTextColor();
83 85
         }
84
-        
86
+
85 87
         if (screen.toolBarHidden != null && screen.toolBarHidden) {
86 88
             hideToolbar();
87 89
         } else {
@@ -112,20 +114,30 @@ public class RnnToolBar extends Toolbar {
112 114
         }
113 115
     }
114 116
 
115
-    private void showToolbar() {
117
+    public void showToolbar(boolean animated) {
116 118
         ActionBar actionBar = ((AppCompatActivity) getContext()).getSupportActionBar();
117 119
         if (actionBar != null) {
120
+            actionBar.setShowHideAnimationEnabled(animated);
118 121
             actionBar.show();
119 122
         }
120 123
     }
121 124
 
122
-    private void hideToolbar() {
125
+    public void hideToolbar(boolean animated) {
123 126
         ActionBar actionBar = ((AppCompatActivity) getContext()).getSupportActionBar();
124 127
         if (actionBar != null) {
128
+            actionBar.setShowHideAnimationEnabled(animated);
125 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 141
     @SuppressWarnings({"ConstantConditions"})
130 142
     public void showBackButton(Screen screen) {
131 143
         ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();

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

@@ -101,9 +101,16 @@ function navigatorSwitchToTab(navigator, params) {
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 111
 function navigatorToggleTabs(navigator, params) {
105 112
   RctActivity.toggleNavigatorTabs({
106
-    hidden: params.to == 'hidden',
113
+    hidden: params.to === 'hidden',
107 114
     animated: !(params.animated === false)
108 115
   });
109 116
 }
@@ -167,5 +174,6 @@ export default {
167 174
   navigatorSetTabBadge,
168 175
   navigatorSetTitle,
169 176
   navigatorSwitchToTab,
170
-  navigatorToggleTabs
177
+  navigatorToggleTabs,
178
+  navigatorToggleNavBar
171 179
 }