Skip to content

Commit c1d87f9

Browse files
dryganetsberickson1
authored andcommitted
Navigation API extracted to the extension (microsoft#145)
* Removed Navigation API from reactxp and moved to extension * Updated samples with reactxp-navigation
1 parent a921b20 commit c1d87f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2923
-303
lines changed

extensions/navigation/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
node_modules
3+
.DS_Store

extensions/navigation/.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!dist

docs/docs/components/navigator.md renamed to extensions/navigation/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
---
2-
id: components/navigator
1+
d: components/navigator
32
title: Navigator
43
layout: docs
54
category: Components
@@ -231,3 +230,4 @@ transitionStarted: (progress?: RX.AnimatedValue,
231230
toIndex?: number, fromIndex?: number) => void = undefined;
232231
```
233232

233+
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./dist/native-common/Navigator');

extensions/navigation/index.ios.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./dist/native-common/Navigator');

extensions/navigation/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
3+
// Export web by default. Other platforms have custom index.[platform].js files
4+
module.exports = require('./dist/web/Navigator');
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./dist/native-common/Navigator');

extensions/navigation/package.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "reactxp-navigation",
3+
"version": "1.0.5",
4+
"description": "Plugin for ReactXP that provides a navigation framework",
5+
"scripts": {
6+
"build": "tsc",
7+
"tslint": "tslint --project tsconfig.json -r tslint.json --fix || true"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/Microsoft/reactxp/tree/master/extensions/navigation"
12+
},
13+
"keywords": [
14+
"react-native",
15+
"reactxp",
16+
"react"
17+
],
18+
"dependencies": {
19+
"@types/lodash": "^4.14.62",
20+
"@types/node": "^6.0.65",
21+
"assert": "^1.3.0",
22+
"lodash": "^4.17.1",
23+
"rebound": "^0.0.13",
24+
"react-native-deprecated-custom-components": "^0.1.1",
25+
"reactxp-experimental-navigation": "^1.0.6"
26+
},
27+
"peerDependencies": {
28+
"react": "^0.14.8",
29+
"react-dom": "^15.4.1",
30+
"react-native": "^0.42.0"
31+
},
32+
"devDependencies": {
33+
"reactxp": "^0.42.0-rc.25",
34+
"typescript": "2.4.1",
35+
"tslint": "^5.0.0"
36+
},
37+
"author": "ReactXP Team <[email protected]>",
38+
"license": "MIT",
39+
"types": "dist/web/Navigator.d.ts"
40+
}
+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/**
2+
* Types.ts
3+
*
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
5+
* Licensed under the MIT license.
6+
* Type definitions for reactxp-naviigation extension.
7+
*/
8+
9+
// Use only for type data
10+
import React = require('react');
11+
import RX = require('reactxp');
12+
13+
export type ReactNode = React.ReactNode;
14+
15+
//
16+
// Navigator
17+
// ----------------------------------------------------------------------
18+
export enum NavigatorSceneConfigType {
19+
FloatFromRight,
20+
FloatFromLeft,
21+
FloatFromBottom,
22+
Fade,
23+
FadeWithSlide
24+
}
25+
26+
export interface NavigatorRoute {
27+
routeId: number;
28+
// Route's animation configuration
29+
sceneConfigType: NavigatorSceneConfigType;
30+
31+
// NOTE: The following props are for the experimental navigator.
32+
// They aren't considered when working with the standard navigator.
33+
// Optional gesture response distance override
34+
// 0 is equivalent to disabling gestures
35+
gestureResponseDistance?: number;
36+
// Optional custom scene config
37+
customSceneConfig?: CustomNavigatorSceneConfig;
38+
}
39+
40+
// NOTE: Experimental navigator only
41+
export type NavigationTransitionSpec = {
42+
duration?: number;
43+
44+
// NOTE: Elastic and bounce easing will not work as expected due to how the navigator interpolates styles
45+
easing?: RX.Types.Animated.EasingFunction;
46+
};
47+
48+
// NOTE: Experimental navigator only
49+
export type NavigationTransitionStyleConfig = {
50+
// By default input range is defined as [index - 1, index, index + 1];
51+
// Input and output ranges must contain the same number of elements
52+
inputRange?: number[];
53+
opacityOutput: number | number[];
54+
scaleOutput: number | number[];
55+
translateXOutput: number | number[];
56+
translateYOutput: number | number[];
57+
};
58+
59+
// NOTE: Experimental navigator only
60+
export type CustomNavigatorSceneConfig = {
61+
// Optional transition styles
62+
transitionStyle?: (sceneIndex: number, sceneDimensions: RX.Types.Dimensions) => NavigationTransitionStyleConfig;
63+
// Optional overrides for duration, easing, and timing
64+
transitionSpec?: NavigationTransitionSpec;
65+
// Optional cardStyle override
66+
cardStyle?: RX.Types.ViewStyleRuleSet;
67+
// Optionally hide drop shadow
68+
hideShadow?: boolean;
69+
// Optionally flip the visual order of the last two scenes
70+
presentBelowPrevious?: boolean;
71+
};
72+
73+
export interface NavigatorProps extends RX.CommonProps {
74+
renderScene: (route: NavigatorRoute) => JSX.Element;
75+
navigateBackCompleted?: () => void;
76+
// NOTE: Arguments are only passed to transitionStarted by the experimental navigator
77+
transitionStarted?: (progress?: RX.Types.AnimatedValue,
78+
toRouteId?: string, fromRouteId?: string,
79+
toIndex?: number, fromIndex?: number) => void;
80+
transitionCompleted?: () => void;
81+
cardStyle?: RX.Types.ViewStyleRuleSet;
82+
children?: ReactNode;
83+
// Selector of the navigator delegate. Currently make difference only in react-native.
84+
delegateSelector?: NavigatorDelegateSelector;
85+
}
86+
87+
export enum CommandType {
88+
Push,
89+
Pop,
90+
Replace
91+
}
92+
93+
export interface CommandParam {
94+
route?: NavigatorRoute;
95+
value?: number;
96+
}
97+
98+
export interface NavigationCommand {
99+
type: CommandType;
100+
param: CommandParam;
101+
}
102+
103+
// Empty state
104+
export interface NavigatorState {
105+
}
106+
107+
export abstract class Navigator<S> extends React.Component<NavigatorProps, S> {
108+
abstract push(route: NavigatorRoute): void;
109+
abstract pop(): void;
110+
abstract replace(route: NavigatorRoute): void;
111+
abstract replacePrevious(route: NavigatorRoute): void;
112+
abstract replaceAtIndex(route: NavigatorRoute, index: number): void;
113+
abstract immediatelyResetRouteStack(nextRouteStack: NavigatorRoute[]): void;
114+
abstract popToRoute(route: NavigatorRoute): void;
115+
abstract popToTop(): void;
116+
abstract getCurrentRoutes(): NavigatorRoute[];
117+
}
118+
119+
export interface NavigatorDelegateSelector {
120+
getNavigatorDelegate(navigator: Navigator<NavigatorState>): NavigatorDelegate;
121+
}
122+
123+
export abstract class NavigatorDelegate {
124+
protected _owner: Navigator<NavigatorState>;
125+
126+
constructor(navigator: Navigator<NavigatorState>) {
127+
this._owner = navigator;
128+
}
129+
130+
onBackPress = (): boolean => {
131+
const routes = this.getRoutes();
132+
if (routes.length > 1) {
133+
this.handleBackPress();
134+
135+
if (this._owner.props.navigateBackCompleted) {
136+
this._owner.props.navigateBackCompleted();
137+
}
138+
139+
// Indicate that we handled the event.
140+
return true;
141+
}
142+
143+
return false;
144+
}
145+
146+
abstract getRoutes(): NavigatorRoute[];
147+
abstract immediatelyResetRouteStack(nextRouteStack: NavigatorRoute[]): void;
148+
abstract render(): JSX.Element;
149+
abstract processCommand(commandQueue: NavigationCommand[]): void;
150+
abstract handleBackPress(): void;
151+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* lodashMini.ts
3+
*
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
5+
* Licensed under the MIT license.
6+
*
7+
* Imports a subset of lodash library needed for ReactXP's implementation.
8+
*/
9+
10+
import assign = require('lodash/assign');
11+
import clone = require('lodash/clone');
12+
import cloneDeep = require('lodash/cloneDeep');
13+
import findIndex = require('lodash/findIndex');
14+
import flatten = require('lodash/flatten');
15+
import get = require('lodash/get');
16+
import isArray = require('lodash/isArray');
17+
import isEmpty = require('lodash/isEmpty');
18+
import isEqual = require('lodash/isEqual');
19+
import isNumber = require('lodash/isNumber');
20+
import map = require('lodash/map');
21+
import mapValues = require('lodash/mapValues');
22+
23+
export interface Dictionary<T> {
24+
[index: string]: T;
25+
}
26+
27+
export {
28+
assign,
29+
clone,
30+
cloneDeep,
31+
findIndex,
32+
flatten,
33+
get,
34+
isArray,
35+
isEmpty,
36+
isEqual,
37+
isNumber,
38+
map,
39+
mapValues,
40+
};

0 commit comments

Comments
 (0)