Browse Source

merged from master

Daniel Zlotin 8 years ago
parent
commit
54b70d898a

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

@@ -464,4 +464,7 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
464 464
                 break;
465 465
         }
466 466
     }
467
+
468
+    public void showFAB(ReadableMap params) {
469
+    }
467 470
 }

+ 3
- 4
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java View File

@@ -4,9 +4,8 @@ import android.graphics.Color;
4 4
 import android.graphics.drawable.Drawable;
5 5
 import android.os.AsyncTask;
6 6
 import android.os.Bundle;
7
-import android.view.Menu;
7
+import android.support.design.widget.CoordinatorLayout;
8 8
 import android.view.View;
9
-import android.widget.FrameLayout;
10 9
 
11 10
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
12 11
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
@@ -38,7 +37,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
38 37
     private static boolean DEFAULT_TAB_INACTIVE_TITLES = true;
39 38
 
40 39
     private AHBottomNavigation mBottomNavigation;
41
-    private FrameLayout mContentFrame;
40
+    private CoordinatorLayout mContentFrame;
42 41
     private ArrayList<ScreenStack> mScreenStacks;
43 42
     private int mCurrentStackPosition = -1;
44 43
 
@@ -50,7 +49,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
50 49
         setContentView(R.layout.bottom_tab_activity);
51 50
         mToolbar = (RnnToolBar) findViewById(R.id.toolbar);
52 51
         mBottomNavigation = (AHBottomNavigation) findViewById(R.id.bottom_tab_bar);
53
-        mContentFrame = (FrameLayout) findViewById(R.id.contentFrame);
52
+        mContentFrame = (CoordinatorLayout) findViewById(R.id.contentFrame);
54 53
 
55 54
         final ArrayList<Screen> screens = (ArrayList<Screen>) getIntent().getSerializableExtra(EXTRA_SCREENS);
56 55
         final Drawer drawer = (Drawer) getIntent().getSerializableExtra(DRAWER_PARAMS);

+ 17
- 2
android/app/src/main/java/com/reactnativenavigation/activities/SingleScreenActivity.java View File

@@ -1,7 +1,8 @@
1 1
 package com.reactnativenavigation.activities;
2 2
 
3
-import android.widget.FrameLayout;
3
+import android.support.design.widget.CoordinatorLayout;
4 4
 
5
+import com.facebook.react.bridge.ReadableMap;
5 6
 import com.reactnativenavigation.R;
6 7
 import com.reactnativenavigation.core.RctManager;
7 8
 import com.reactnativenavigation.core.objects.Drawer;
@@ -34,7 +35,7 @@ public class SingleScreenActivity extends BaseReactActivity {
34 35
         setupDrawer(screen, drawer, R.id.drawerFrame, R.id.drawerLayout);
35 36
 
36 37
         mScreenStack = new ScreenStack(this);
37
-        FrameLayout contentFrame = (FrameLayout) findViewById(R.id.contentFrame);
38
+        CoordinatorLayout contentFrame = (CoordinatorLayout) findViewById(R.id.contentFrame);
38 39
         assert contentFrame != null;
39 40
         contentFrame.addView(mScreenStack);
40 41
         mScreenStack.push(screen);
@@ -107,4 +108,18 @@ public class SingleScreenActivity extends BaseReactActivity {
107 108
     protected void removeAllReactViews() {
108 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
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/modal/RnnModal.java View File

@@ -97,6 +97,7 @@ public class RnnModal extends Dialog implements DialogInterface.OnDismissListene
97 97
 
98 98
     @Override
99 99
     public void onDismiss(DialogInterface dialog) {
100
+        mScreenStack.removeAllReactViews();
100 101
         ModalController.getInstance().remove();
101 102
         // After modal is dismissed, update Toolbar with screen from parent activity or previously displayed modal
102 103
         BaseReactActivity context = ContextProvider.getActivityContext();

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

@@ -55,7 +55,7 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
55 55
 
56 56
             context.startActivity(intent);
57 57
             //TODO add abstract isRoot() instead of instanceof?
58
-            if(ContextProvider.getActivityContext() instanceof RootActivity) {
58
+            if (ContextProvider.getActivityContext() instanceof RootActivity) {
59 59
                 context.overridePendingTransition(0, 0);
60 60
             }
61 61
 
@@ -66,7 +66,7 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
66 66
 
67 67
     private ArrayList<Screen> createScreens(ReadableArray screens) {
68 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 70
             ret.add(new Screen(screens.getMap(i)));
71 71
         }
72 72
         return ret;
@@ -87,7 +87,7 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
87 87
             intent.putExtras(extras);
88 88
 
89 89
             context.startActivity(intent);
90
-            if(ContextProvider.getActivityContext() instanceof RootActivity) {
90
+            if (ContextProvider.getActivityContext() instanceof RootActivity) {
91 91
                 context.overridePendingTransition(0, 0);
92 92
             }
93 93
 
@@ -306,15 +306,15 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
306 306
     public void dismissAllModals(final ReadableMap params) {
307 307
         final BaseReactActivity context = ContextProvider.getActivityContext();
308 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,4 +328,19 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
328 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,11 +1,9 @@
1 1
 package com.reactnativenavigation.utils;
2 2
 
3 3
 import android.content.Context;
4
-import android.content.res.Resources;
5 4
 import android.graphics.PorterDuff;
6 5
 import android.graphics.PorterDuffColorFilter;
7 6
 import android.graphics.drawable.Drawable;
8
-import android.util.DisplayMetrics;
9 7
 
10 8
 /**
11 9
  * Created by guyc on 23/04/16.
@@ -19,14 +17,12 @@ public class ImageUtils {
19 17
     /**
20 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 21
      * @param context Context to get resources and device specific display metrics
24 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
 }

+ 21
- 0
android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java View File

@@ -0,0 +1,21 @@
1
+package com.reactnativenavigation.utils;
2
+
3
+import android.view.View;
4
+import android.view.ViewTreeObserver;
5
+
6
+public class ViewUtils {
7
+    public static void runOnPreDraw(final View view, final Runnable task) {
8
+        view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
9
+            @Override
10
+            public boolean onPreDraw() {
11
+                if (!view.getViewTreeObserver().isAlive()) {
12
+                    return true;
13
+                }
14
+                view.getViewTreeObserver().removeOnPreDrawListener(this);
15
+                task.run();
16
+                return true;
17
+            }
18
+        });
19
+    }
20
+}
21
+

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

@@ -2,9 +2,9 @@ package com.reactnativenavigation.views;
2 2
 
3 3
 import android.animation.LayoutTransition;
4 4
 import android.content.Context;
5
+import android.support.design.widget.CoordinatorLayout;
5 6
 import android.util.AttributeSet;
6 7
 import android.view.ViewGroup;
7
-import android.widget.FrameLayout;
8 8
 
9 9
 import com.facebook.react.ReactInstanceManager;
10 10
 import com.reactnativenavigation.activities.BaseReactActivity;
@@ -15,7 +15,7 @@ import java.util.Stack;
15 15
 
16 16
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
17 17
 
18
-public class ScreenStack extends FrameLayout {
18
+public class ScreenStack extends android.support.design.widget.CoordinatorLayout {
19 19
 
20 20
     private static final int DISAPPEAR_ANIMATION_DELAY = 200;
21 21
 
@@ -163,7 +163,7 @@ public class ScreenStack extends FrameLayout {
163 163
     public void addToScreen(ViewGroup parent) {
164 164
         mStack.peek().view.onReAddToScreen();
165 165
 
166
-        parent.addView(this, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
166
+        parent.addView(this, new CoordinatorLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
167 167
     }
168 168
 
169 169
     public void removeAllReactViews() {

+ 1
- 1
android/app/src/main/res/layout/bottom_tab_activity.xml View File

@@ -27,7 +27,7 @@
27 27
         android:layout_height="0dp"
28 28
         android:layout_weight="1">
29 29
 
30
-        <FrameLayout
30
+        <android.support.design.widget.CoordinatorLayout
31 31
             android:id="@+id/contentFrame"
32 32
             android:layout_width="match_parent"
33 33
             android:layout_height="0dp"

+ 1
- 1
android/app/src/main/res/layout/single_screen_activity.xml View File

@@ -23,7 +23,7 @@
23 23
         android:layout_width="match_parent"
24 24
         android:layout_height="match_parent">
25 25
 
26
-        <FrameLayout
26
+        <android.support.design.widget.CoordinatorLayout
27 27
             android:id="@+id/contentFrame"
28 28
             android:layout_width="match_parent"
29 29
             android:layout_height="match_parent" />

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

@@ -6,7 +6,7 @@ import {
6 6
   TouchableOpacity,
7 7
   StyleSheet
8 8
 } from 'react-native';
9
-import { connect } from 'react-redux';
9
+import {connect} from 'react-redux';
10 10
 import * as counterActions from '../reducers/counter/actions';
11 11
 import * as appActions from '../reducers/app/actions';
12 12
 
@@ -23,6 +23,10 @@ class LoginScreen extends Component {
23 23
     super(props);
24 24
   }
25 25
 
26
+  componentWillUnmount() {
27
+    console.log('Component-Lifecycle', 'componentWillUnmount', 'LoginScreen');
28
+  }
29
+
26 30
   render() {
27 31
     return (
28 32
       <View style={{flex: 1, padding: 20}}>
@@ -39,6 +43,10 @@ class LoginScreen extends Component {
39 43
           <Text style={styles.button}>Login</Text>
40 44
         </TouchableOpacity>
41 45
 
46
+        <TouchableOpacity onPress={ this.onShowModalPress.bind(this) }>
47
+          <Text style={styles.button}>Show another login as modal</Text>
48
+        </TouchableOpacity>
49
+
42 50
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
43 51
         <Text style={{fontWeight: '500'}}>Number prop: {this.props.num}</Text>
44 52
         <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>
@@ -48,12 +56,42 @@ class LoginScreen extends Component {
48 56
       </View>
49 57
     );
50 58
   }
59
+
51 60
   onIncrementPress() {
52 61
     this.props.dispatch(counterActions.increment());
53 62
   }
63
+
54 64
   onLoginPress() {
55 65
     this.props.dispatch(appActions.login());
56 66
   }
67
+
68
+  onShowModalPress() {
69
+    this.props.navigator.showModal({
70
+      screen: 'example.LoginScreen',
71
+      title: 'Login',
72
+      passProps: {
73
+        str: 'This is a prop passed in \'startSingleScreenApp()\'!',
74
+        obj: {
75
+          str: 'This is a prop passed in an object!',
76
+          arr: [
77
+            {
78
+              str: 'This is a prop in an object in an array in an object!'
79
+            }
80
+          ],
81
+          arr2: [
82
+            [
83
+              'array of strings',
84
+              'with two strings'
85
+            ],
86
+            [
87
+              1, 2, 3
88
+            ]
89
+          ]
90
+        },
91
+        num: 1234
92
+      }
93
+    });
94
+  }
57 95
 }
58 96
 
59 97
 const styles = StyleSheet.create({
@@ -61,13 +99,13 @@ const styles = StyleSheet.create({
61 99
     textAlign: 'center',
62 100
     fontSize: 18,
63 101
     marginBottom: 10,
64
-    marginTop:10,
102
+    marginTop: 10,
65 103
   },
66 104
   button: {
67 105
     textAlign: 'center',
68 106
     fontSize: 18,
69 107
     marginBottom: 10,
70
-    marginTop:10,
108
+    marginTop: 10,
71 109
     color: 'blue'
72 110
   }
73 111
 });

+ 6
- 1
src/Screen.js View File

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

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

@@ -197,6 +197,11 @@ function setupDrawer(drawerParams) {
197 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 205
 export default {
201 206
   startTabBasedApp,
202 207
   startSingleScreenApp,
@@ -207,6 +212,7 @@ export default {
207 212
   showModal,
208 213
   dismissModal,
209 214
   dismissAllModals,
215
+  showFAB,
210 216
   navigatorSetButtons,
211 217
   navigatorSetTabBadge,
212 218
   navigatorSetTitle,