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

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

1
 package com.reactnativenavigation.activities;
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
 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;
34
         setupDrawer(screen, drawer, R.id.drawerFrame, R.id.drawerLayout);
35
         setupDrawer(screen, drawer, R.id.drawerFrame, R.id.drawerLayout);
35
 
36
 
36
         mScreenStack = new ScreenStack(this);
37
         mScreenStack = new ScreenStack(this);
37
-        FrameLayout contentFrame = (FrameLayout) findViewById(R.id.contentFrame);
38
+        CoordinatorLayout contentFrame = (CoordinatorLayout) findViewById(R.id.contentFrame);
38
         assert contentFrame != null;
39
         assert contentFrame != null;
39
         contentFrame.addView(mScreenStack);
40
         contentFrame.addView(mScreenStack);
40
         mScreenStack.push(screen);
41
         mScreenStack.push(screen);
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
 }

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

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

+ 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
 }

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

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
 
2
 
3
 import android.animation.LayoutTransition;
3
 import android.animation.LayoutTransition;
4
 import android.content.Context;
4
 import android.content.Context;
5
+import android.support.design.widget.CoordinatorLayout;
5
 import android.util.AttributeSet;
6
 import android.util.AttributeSet;
6
 import android.view.ViewGroup;
7
 import android.view.ViewGroup;
7
-import android.widget.FrameLayout;
8
 
8
 
9
 import com.facebook.react.ReactInstanceManager;
9
 import com.facebook.react.ReactInstanceManager;
10
 import com.reactnativenavigation.activities.BaseReactActivity;
10
 import com.reactnativenavigation.activities.BaseReactActivity;
15
 
15
 
16
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
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
     private static final int DISAPPEAR_ANIMATION_DELAY = 200;
20
     private static final int DISAPPEAR_ANIMATION_DELAY = 200;
21
 
21
 
163
     public void addToScreen(ViewGroup parent) {
163
     public void addToScreen(ViewGroup parent) {
164
         mStack.peek().view.onReAddToScreen();
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
     public void removeAllReactViews() {
169
     public void removeAllReactViews() {

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

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

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

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

+ 41
- 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
 
23
     super(props);
23
     super(props);
24
   }
24
   }
25
 
25
 
26
+  componentWillUnmount() {
27
+    console.log('Component-Lifecycle', 'componentWillUnmount', 'LoginScreen');
28
+  }
29
+
26
   render() {
30
   render() {
27
     return (
31
     return (
28
       <View style={{flex: 1, padding: 20}}>
32
       <View style={{flex: 1, padding: 20}}>
39
           <Text style={styles.button}>Login</Text>
43
           <Text style={styles.button}>Login</Text>
40
         </TouchableOpacity>
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
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
50
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
43
         <Text style={{fontWeight: '500'}}>Number prop: {this.props.num}</Text>
51
         <Text style={{fontWeight: '500'}}>Number prop: {this.props.num}</Text>
44
         <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>
52
         <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>
48
       </View>
56
       </View>
49
     );
57
     );
50
   }
58
   }
59
+
51
   onIncrementPress() {
60
   onIncrementPress() {
52
     this.props.dispatch(counterActions.increment());
61
     this.props.dispatch(counterActions.increment());
53
   }
62
   }
63
+
54
   onLoginPress() {
64
   onLoginPress() {
55
     this.props.dispatch(appActions.login());
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
 const styles = StyleSheet.create({
97
 const styles = StyleSheet.create({
61
     textAlign: 'center',
99
     textAlign: 'center',
62
     fontSize: 18,
100
     fontSize: 18,
63
     marginBottom: 10,
101
     marginBottom: 10,
64
-    marginTop:10,
102
+    marginTop: 10,
65
   },
103
   },
66
   button: {
104
   button: {
67
     textAlign: 'center',
105
     textAlign: 'center',
68
     fontSize: 18,
106
     fontSize: 18,
69
     marginBottom: 10,
107
     marginBottom: 10,
70
-    marginTop:10,
108
+    marginTop: 10,
71
     color: 'blue'
109
     color: 'blue'
72
   }
110
   }
73
 });
111
 });

+ 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,