Browse Source

basic FAB support

Daniel Zlotin 8 years ago
parent
commit
7ce30d9f3d

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

464
                 break;
464
                 break;
465
         }
465
         }
466
     }
466
     }
467
+
468
+    public void showFAB(ReadableMap params) {
469
+    }
467
 }
470
 }

+ 15
- 0
android/app/src/main/java/com/reactnativenavigation/activities/SingleScreenActivity.java View File

2
 
2
 
3
 import android.support.design.widget.CoordinatorLayout;
3
 import android.support.design.widget.CoordinatorLayout;
4
 
4
 
5
+import com.facebook.react.bridge.ReadableMap;
5
 import com.reactnativenavigation.R;
6
 import com.reactnativenavigation.R;
6
 import com.reactnativenavigation.core.RctManager;
7
 import com.reactnativenavigation.core.RctManager;
7
 import com.reactnativenavigation.core.objects.Drawer;
8
 import com.reactnativenavigation.core.objects.Drawer;
107
     protected void removeAllReactViews() {
108
     protected void removeAllReactViews() {
108
         mScreenStack.removeAllReactViews();
109
         mScreenStack.removeAllReactViews();
109
     }
110
     }
111
+
112
+    @Override
113
+    public void showFAB(ReadableMap params) {
114
+//        FloatingActionButton fab = new FloatingActionButton(this);
115
+//        fab.setImageDrawable(IconUtils.getIcon(this, params.getString("icon")));
116
+//        fab.setBackgroundColor(Color.parseColor(params.getString("backgroundColor")));
117
+//        fab.setImageResource(R.drawable.notification_background);
118
+//        CoordinatorLayout content = (CoordinatorLayout) findViewById(R.id.contentFrame);
119
+//        CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
120
+//        layoutParams.gravity = Gravity.BOTTOM | Gravity.END;
121
+//        int m = (int) ImageUtils.convertDpToPixel(16, this);
122
+//        layoutParams.setMargins(m, m, m, m);
123
+//        content.addView(fab, layoutParams);
124
+    }
110
 }
125
 }

+ 26
- 11
android/app/src/main/java/com/reactnativenavigation/modules/RctActivityModule.java View File

55
 
55
 
56
             context.startActivity(intent);
56
             context.startActivity(intent);
57
             //TODO add abstract isRoot() instead of instanceof?
57
             //TODO add abstract isRoot() instead of instanceof?
58
-            if(ContextProvider.getActivityContext() instanceof RootActivity) {
58
+            if (ContextProvider.getActivityContext() instanceof RootActivity) {
59
                 context.overridePendingTransition(0, 0);
59
                 context.overridePendingTransition(0, 0);
60
             }
60
             }
61
 
61
 
66
 
66
 
67
     private ArrayList<Screen> createScreens(ReadableArray screens) {
67
     private ArrayList<Screen> createScreens(ReadableArray screens) {
68
         ArrayList<Screen> ret = new ArrayList<>();
68
         ArrayList<Screen> ret = new ArrayList<>();
69
-        for(int i = 0; i < screens.size(); i++) {
69
+        for (int i = 0; i < screens.size(); i++) {
70
             ret.add(new Screen(screens.getMap(i)));
70
             ret.add(new Screen(screens.getMap(i)));
71
         }
71
         }
72
         return ret;
72
         return ret;
87
             intent.putExtras(extras);
87
             intent.putExtras(extras);
88
 
88
 
89
             context.startActivity(intent);
89
             context.startActivity(intent);
90
-            if(ContextProvider.getActivityContext() instanceof RootActivity) {
90
+            if (ContextProvider.getActivityContext() instanceof RootActivity) {
91
                 context.overridePendingTransition(0, 0);
91
                 context.overridePendingTransition(0, 0);
92
             }
92
             }
93
 
93
 
306
     public void dismissAllModals(final ReadableMap params) {
306
     public void dismissAllModals(final ReadableMap params) {
307
         final BaseReactActivity context = ContextProvider.getActivityContext();
307
         final BaseReactActivity context = ContextProvider.getActivityContext();
308
         if (context != null && !context.isFinishing()) {
308
         if (context != null && !context.isFinishing()) {
309
-        context.runOnUiThread(new Runnable() {
310
-            @Override
311
-            public void run() {
312
-                ModalController modalController = ModalController.getInstance();
313
-                if (modalController.isModalDisplayed()) {
314
-                    modalController.dismissAllModals();
309
+            context.runOnUiThread(new Runnable() {
310
+                @Override
311
+                public void run() {
312
+                    ModalController modalController = ModalController.getInstance();
313
+                    if (modalController.isModalDisplayed()) {
314
+                        modalController.dismissAllModals();
315
+                    }
315
                 }
316
                 }
316
-            }
317
-        });
317
+            });
318
         }
318
         }
319
     }
319
     }
320
 
320
 
328
             modalController.dismissModal();
328
             modalController.dismissModal();
329
         }
329
         }
330
     }
330
     }
331
+
332
+    @ReactMethod
333
+    public void showFAB(final ReadableMap params) {
334
+        final BaseReactActivity context = ContextProvider.getActivityContext();
335
+        if (context == null || context.isFinishing()) {
336
+            return;
337
+        }
338
+        context.runOnUiThread(new Runnable() {
339
+            @Override
340
+            public void run() {
341
+                context.showFAB(params);
342
+            }
343
+        });
344
+    }
345
+
331
 }
346
 }

+ 4
- 8
android/app/src/main/java/com/reactnativenavigation/utils/ImageUtils.java View File

1
 package com.reactnativenavigation.utils;
1
 package com.reactnativenavigation.utils;
2
 
2
 
3
 import android.content.Context;
3
 import android.content.Context;
4
-import android.content.res.Resources;
5
 import android.graphics.PorterDuff;
4
 import android.graphics.PorterDuff;
6
 import android.graphics.PorterDuffColorFilter;
5
 import android.graphics.PorterDuffColorFilter;
7
 import android.graphics.drawable.Drawable;
6
 import android.graphics.drawable.Drawable;
8
-import android.util.DisplayMetrics;
9
 
7
 
10
 /**
8
 /**
11
  * Created by guyc on 23/04/16.
9
  * Created by guyc on 23/04/16.
19
     /**
17
     /**
20
      * This method converts dp unit to equivalent pixels, depending on device density.
18
      * This method converts dp unit to equivalent pixels, depending on device density.
21
      *
19
      *
22
-     * @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels
20
+     * @param dp      A value in dp (density independent pixels) unit. Which we need to convert into pixels
23
      * @param context Context to get resources and device specific display metrics
21
      * @param context Context to get resources and device specific display metrics
24
      * @return A float value to represent px equivalent to dp depending on device density
22
      * @return A float value to represent px equivalent to dp depending on device density
25
      */
23
      */
26
-    public static float convertDpToPixel(float dp, Context context){
27
-        Resources resources = context.getResources();
28
-        DisplayMetrics metrics = resources.getDisplayMetrics();
29
-        float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
30
-        return px;
24
+    public static float convertDpToPixel(float dp, Context context) {
25
+        float scale = context.getResources().getDisplayMetrics().density;
26
+        return dp * scale + 0.5f;
31
     }
27
     }
32
 }
28
 }

+ 9
- 3
example-redux/src/screens/LoginScreen.js View File

6
   TouchableOpacity,
6
   TouchableOpacity,
7
   StyleSheet
7
   StyleSheet
8
 } from 'react-native';
8
 } from 'react-native';
9
-import { connect } from 'react-redux';
9
+import {connect} from 'react-redux';
10
 import * as counterActions from '../reducers/counter/actions';
10
 import * as counterActions from '../reducers/counter/actions';
11
 import * as appActions from '../reducers/app/actions';
11
 import * as appActions from '../reducers/app/actions';
12
 
12
 
21
 
21
 
22
   constructor(props) {
22
   constructor(props) {
23
     super(props);
23
     super(props);
24
+    this.props.navigator.showFAB({
25
+      icon: require('../../img/navicon_edit@2x.png'),
26
+      backgroundColor: 'blue'
27
+    });
24
   }
28
   }
25
 
29
 
26
   render() {
30
   render() {
48
       </View>
52
       </View>
49
     );
53
     );
50
   }
54
   }
55
+
51
   onIncrementPress() {
56
   onIncrementPress() {
52
     this.props.dispatch(counterActions.increment());
57
     this.props.dispatch(counterActions.increment());
53
   }
58
   }
59
+
54
   onLoginPress() {
60
   onLoginPress() {
55
     this.props.dispatch(appActions.login());
61
     this.props.dispatch(appActions.login());
56
   }
62
   }
61
     textAlign: 'center',
67
     textAlign: 'center',
62
     fontSize: 18,
68
     fontSize: 18,
63
     marginBottom: 10,
69
     marginBottom: 10,
64
-    marginTop:10,
70
+    marginTop: 10,
65
   },
71
   },
66
   button: {
72
   button: {
67
     textAlign: 'center',
73
     textAlign: 'center',
68
     fontSize: 18,
74
     fontSize: 18,
69
     marginBottom: 10,
75
     marginBottom: 10,
70
-    marginTop:10,
76
+    marginTop: 10,
71
     color: 'blue'
77
     color: 'blue'
72
   }
78
   }
73
 });
79
 });

+ 6
- 1
src/Screen.js View File

93
     return platformSpecific.navigatorSwitchToTab(this, params);
93
     return platformSpecific.navigatorSwitchToTab(this, params);
94
   }
94
   }
95
 
95
 
96
+  showFAB(params = {}) {
97
+    return platformSpecific.showFAB(params);
98
+  }
99
+
96
   setOnNavigatorEvent(callback) {
100
   setOnNavigatorEvent(callback) {
97
     this.navigatorEventHandler = callback;
101
     this.navigatorEventHandler = callback;
98
     if (!this.navigatorEventSubscription) {
102
     if (!this.navigatorEventSubscription) {
101
       _allNavigatorEventHandlers[this.navigatorEventID] = (event) => this.onNavigatorEvent(event);
105
       _allNavigatorEventHandlers[this.navigatorEventID] = (event) => this.onNavigatorEvent(event);
102
     }
106
     }
103
   }
107
   }
108
+
104
   handleDeepLink(params = {}) {
109
   handleDeepLink(params = {}) {
105
     if (!params.link) return;
110
     if (!params.link) return;
106
     const event = {
111
     const event = {
129
 export default class Screen extends Component {
134
 export default class Screen extends Component {
130
   static navigatorStyle = {};
135
   static navigatorStyle = {};
131
   static navigatorButtons = {};
136
   static navigatorButtons = {};
132
-  
137
+
133
   constructor(props) {
138
   constructor(props) {
134
     super(props);
139
     super(props);
135
     if (props.navigatorID) {
140
     if (props.navigatorID) {

+ 6
- 0
src/platformSpecific.android.js View File

197
   return drawer;
197
   return drawer;
198
 }
198
 }
199
 
199
 
200
+function showFAB(params) {
201
+  params.icon = resolveAssetSource(params.icon).uri;
202
+  RctActivity.showFAB(params);
203
+}
204
+
200
 export default {
205
 export default {
201
   startTabBasedApp,
206
   startTabBasedApp,
202
   startSingleScreenApp,
207
   startSingleScreenApp,
207
   showModal,
212
   showModal,
208
   dismissModal,
213
   dismissModal,
209
   dismissAllModals,
214
   dismissAllModals,
215
+  showFAB,
210
   navigatorSetButtons,
216
   navigatorSetButtons,
211
   navigatorSetTabBadge,
217
   navigatorSetTabBadge,
212
   navigatorSetTitle,
218
   navigatorSetTitle,