Skip to content

Commit

Permalink
Merge pull request #245 from grahammendick/single-root
Browse files Browse the repository at this point in the history
  • Loading branch information
grahammendick committed Jun 10, 2019
2 parents 15c3762 + 61a311f commit 51fcdaf
Show file tree
Hide file tree
Showing 65 changed files with 1,402 additions and 726 deletions.
9 changes: 5 additions & 4 deletions NavigationReactNative/sample/medley/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {StateNavigator} from 'navigation';
import {NavigationHandler} from 'navigation-react';
import {addNavigateHandlers, Scene} from 'navigation-react-native';
import {NavigationStack} from 'navigation-react-native';
import Direction from './Direction';

const stateNavigator = new StateNavigator([
Expand All @@ -27,10 +27,11 @@ west.getCrumbStyle = from => from ? 'west_crumb_in' : 'west_crumb_out';
west.getUnmountStyle = from => from ? 'west_in' : 'west_out';

stateNavigator.navigate('north');
addNavigateHandlers(stateNavigator);

export default ({crumb}) => (
export default () => (
<NavigationHandler stateNavigator={stateNavigator}>
<Scene crumb={crumb} />
<NavigationStack
crumbStyle={(from, state) => state.getCrumbStyle(from)}
unmountStyle={(from, state) => state.getUnmountStyle(from)} />
</NavigationHandler>
);
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
Expand Down
29 changes: 5 additions & 24 deletions NavigationReactNative/sample/redux/App.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from 'react';
import {NativeEventEmitter, NativeModules} from 'react-native';
import {StateNavigator} from 'navigation';
import {NavigationHandler} from 'navigation-react';
import {addNavigateHandlers, Scene} from 'navigation-react-native';
import {NavigationStack} from 'navigation-react-native';
import {createStore} from 'redux';
import {Provider} from 'react-redux';
import reducer from './reducer';
import Blinkers from './Blinkers';
import People from './People';
import Person from './Person';

Expand All @@ -21,29 +19,12 @@ person.renderScene = ({id}) => <Person id={id} />;

const store = createStore(reducer);

stateNavigator.onNavigate(() => {
store.dispatch({
type: "NAVIGATE",
payload: {crumb: stateNavigator.stateContext.crumbs.length}
});
});
var navigationEmitter = new NativeEventEmitter(NativeModules.NavigationModule);
navigationEmitter.addListener('PeekNavigate', ({crumb}) => {
store.dispatch({
type: "PEEK",
payload: {crumb}
});
});

stateNavigator.navigate('people');
addNavigateHandlers(stateNavigator);

export default ({crumb}) => (
export default () => (
<Provider store={store}>
<Blinkers crumb={crumb}>
<NavigationHandler stateNavigator={stateNavigator}>
<Scene crumb={crumb} />
</NavigationHandler>
</Blinkers>
<NavigationHandler stateNavigator={stateNavigator}>
<NavigationStack />
</NavigationHandler>
</Provider>
);
26 changes: 0 additions & 26 deletions NavigationReactNative/sample/redux/Blinkers.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
Expand Down
5 changes: 1 addition & 4 deletions NavigationReactNative/sample/redux/ios/redux/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@

#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <React/RCTBridge.h>
#import "NVApplicationHostDelegate.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, NVApplicationHostDelegate>
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>

@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) RCTBridge *bridge;

@end
18 changes: 9 additions & 9 deletions NavigationReactNative/sample/redux/ios/redux/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "NVSceneController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

NSString *title = @"People";
NSString *appKey = @"redux";
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"redux"
initialProperties:nil];

UIViewController *sceneController = [[NVSceneController alloc] init:0 tab:0 title:title appKey:appKey];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:sceneController];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

self.window.rootViewController = navigationController;
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
Expand Down
47 changes: 32 additions & 15 deletions NavigationReactNative/sample/twitter/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import {Platform} from 'react-native';
import {StateNavigator} from 'navigation';
import {NavigationHandler} from 'navigation-react';
import {addNavigateHandlers, Scene} from 'navigation-react-native';
import {NavigationStack, TabBarIOS, TabBarItemIOS} from 'navigation-react-native';
import Home from './Home';
import Notifications from './Notifications';
import Tweet from './Tweet';
Expand All @@ -20,22 +21,38 @@ notifications.renderScene = () => <Notifications follows={getFollows()} />;
tweet.renderScene = ({id}) => <Tweet tweet={getTweet(id)} />;
timeline.renderScene = ({id}) => <Timeline timeline={getTimeline(id)} />;

for(var key in stateNavigator.states) {
var state = stateNavigator.states[key];
state.getCrumbStyle = from => from ? 'scale_in' : 'scale_out';
state.getUnmountStyle = from => from ? 'slide_in' : 'slide_out';
}

timeline.getTitle = ({sceneTitle}) => sceneTitle;
var getSceneTitle = (state, data) => {
var {getTitle, title} = state;
return getTitle ? getTitle(data) : title;
}

var stateNavigators = [stateNavigator, new StateNavigator(stateNavigator)];
var notificationsNavigator = new StateNavigator(stateNavigator);
stateNavigator.navigate('home');
stateNavigators[1].navigate('notifications');

addNavigateHandlers(stateNavigators);

export default ({crumb, tab = 0}) => (
<NavigationHandler stateNavigator={stateNavigators[tab]}>
<Scene crumb={crumb} tab={tab} />
</NavigationHandler>
export default () => (
Platform.OS === 'ios' ? (
<TabBarIOS>
<TabBarItemIOS title="Home">
<NavigationHandler stateNavigator={stateNavigator}>
<NavigationStack title={getSceneTitle} />
</NavigationHandler>
</TabBarItemIOS>
<TabBarItemIOS title="Notifications" onPress={() => {
if (!notificationsNavigator.stateContext.state)
notificationsNavigator.navigate('notifications');
}}>
<NavigationHandler stateNavigator={notificationsNavigator}>
<NavigationStack title={getSceneTitle} />
</NavigationHandler>
</TabBarItemIOS>
</TabBarIOS>
) : (
<NavigationHandler stateNavigator={stateNavigator}>
<NavigationStack
crumbStyle={from => from ? 'scale_in' : 'scale_out'}
unmountStyle={from => from ? 'slide_in' : 'slide_out'}>
</NavigationStack>
</NavigationHandler>
)
);
2 changes: 1 addition & 1 deletion NavigationReactNative/sample/twitter/Home.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default ({tweets, follows}) => (
<Tweets tweets={tweets} />
</ScrollView>
</View>
<View key={1}>
<View key={2}>
<ScrollView style={styles.view}>
<Notifications follows={follows} />
</ScrollView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
*/

#import <UIKit/UIKit.h>
#import <React/RCTBridge.h>
#import "NVApplicationHostDelegate.h"

@interface AppDelegate : UIResponder <NVApplicationHostDelegate>
@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) RCTBridge *bridge;

@end
35 changes: 17 additions & 18 deletions NavigationReactNative/sample/twitter/ios/twitter/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,32 @@
*/

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "NVSceneController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
NSURL *jsCodeLocation;

#ifdef DEBUG
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"twitter"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

self.bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation moduleProvider:nil launchOptions:launchOptions];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

NSArray *tabs = @[@"Home", @"Notifications"];
NSString *appKey = @"twitter";

NSMutableArray *controllers = [[NSMutableArray alloc] init];
for(NSInteger tab = 0; tab < [tabs count]; tab++) {
UIViewController *sceneController = [[NVSceneController alloc] init:0 tab:tab title:tabs[tab] appKey:appKey];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:sceneController];
navigationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:tabs[tab] image:nil tag:tab];
[controllers addObject:navigationController];
}

UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:controllers];
self.window.rootViewController = tabBarController;
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
Expand Down
11 changes: 3 additions & 8 deletions NavigationReactNative/sample/web/App.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import React from 'react';
import {NavigationHandler} from 'navigation-react';
import {addNavigateHandlers, Scene} from 'navigation-react-native';
import {NavigationStack} from 'navigation-react-native';
import createStateNavigator from './createStateNavigator';

var stateNavigator = createStateNavigator();

const {detail} = stateNavigator.states;
detail.getSharedElements = ({color}) => [color];

stateNavigator.navigate('grid');
addNavigateHandlers(stateNavigator);

export default ({crumb}) => (
export default () => (
<NavigationHandler stateNavigator={stateNavigator}>
<Scene crumb={crumb} />
<NavigationStack sharedElements={(_, {color}) => color && [color]} />
</NavigationHandler>
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
Expand Down
5 changes: 1 addition & 4 deletions NavigationReactNative/sample/web/ios/web/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
*/

#import <UIKit/UIKit.h>
#import <React/RCTBridge.h>
#import "NVApplicationHostDelegate.h"

@interface AppDelegate : UIResponder <NVApplicationHostDelegate>
@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) RCTBridge *bridge;

@end

0 comments on commit 51fcdaf

Please sign in to comment.