|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import RX = require('reactxp'); |
6 | | -import { default as RXVideo } from 'reactxp-video'; |
7 | 6 |
|
8 | | -import ProgressIndicator from './ProgressIndicator'; |
9 | | -import ToggleSwitch from './ToggleSwitch'; |
| 7 | +import MainPanel = require('./MainPanel'); |
| 8 | +import SecondPanel = require('./SecondPanel'); |
10 | 9 |
|
11 | | -interface AppState { |
12 | | - toggleValue?: boolean; |
13 | | - progressValue?: number; |
| 10 | +enum NavigationRouteId { |
| 11 | + MainPanel, |
| 12 | + SecondPanel |
14 | 13 | } |
15 | 14 |
|
16 | 15 | const styles = { |
17 | | - scroll: RX.Styles.createScrollViewStyle({ |
18 | | - alignSelf: 'stretch', |
| 16 | + navCardStyle: RX.Styles.createViewStyle({ |
19 | 17 | backgroundColor: '#f5fcff' |
20 | | - }), |
21 | | - container: RX.Styles.createViewStyle({ |
22 | | - padding: 16, |
23 | | - justifyContent: 'center', |
24 | | - alignItems: 'center' |
25 | | - }), |
26 | | - helloWorld: RX.Styles.createTextStyle({ |
27 | | - fontSize: 48, |
28 | | - fontWeight: 'bold', |
29 | | - marginBottom: 28 |
30 | | - }), |
31 | | - welcome: RX.Styles.createTextStyle({ |
32 | | - fontSize: 32, |
33 | | - marginBottom: 12 |
34 | | - }), |
35 | | - instructions: RX.Styles.createTextStyle({ |
36 | | - fontSize: 16, |
37 | | - color: '#aaa', |
38 | | - marginBottom: 16 |
39 | | - }), |
40 | | - docLink: RX.Styles.createLinkStyle({ |
41 | | - fontSize: 16, |
42 | | - color: 'blue', |
43 | | - marginBottom: 16 |
44 | | - }), |
45 | | - titleText: RX.Styles.createTextStyle({ |
46 | | - fontSize: 16, |
47 | | - textAlign: 'center', |
48 | | - marginTop: 12, |
49 | | - color: 'black' |
50 | | - }), |
51 | | - videoTitleText: RX.Styles.createTextStyle({ |
52 | | - marginBottom: 8 |
53 | | - }), |
54 | | - progressMargin: RX.Styles.createViewStyle({ |
55 | | - margin: 8 |
56 | | - }), |
57 | | - video: RX.Styles.createViewStyle({ |
58 | | - height: 176, |
59 | | - width: 320 |
60 | 18 | }) |
61 | 19 | }; |
62 | 20 |
|
63 | | -class App extends RX.Component<null, AppState> { |
64 | | - private _translationValue: RX.Animated.Value; |
65 | | - private _animatedStyle: RX.Types.AnimatedTextStyleRuleSet; |
66 | | - private _progressTimerToken: number; |
| 21 | +class App extends RX.Component<null, null> { |
| 22 | + private _navigator: RX.Navigator; |
67 | 23 |
|
68 | | - constructor() { |
69 | | - super(); |
70 | | - |
71 | | - this._translationValue = new RX.Animated.Value(-100); |
72 | | - this._animatedStyle = RX.Styles.createAnimatedTextStyle({ |
73 | | - transform: [ |
74 | | - { |
75 | | - translateY: this._translationValue |
76 | | - } |
77 | | - ] |
78 | | - }); |
79 | | - |
80 | | - this.state = { |
81 | | - toggleValue: true, |
82 | | - progressValue: 0 |
83 | | - }; |
| 24 | + componentDidMount() { |
| 25 | + this._navigator.immediatelyResetRouteStack([{ |
| 26 | + routeId: NavigationRouteId.MainPanel, |
| 27 | + sceneConfigType: RX.Types.NavigatorSceneConfigType.Fade |
| 28 | + }]); |
84 | 29 | } |
85 | 30 |
|
86 | | - componentDidMount() { |
87 | | - let animation = RX.Animated.timing(this._translationValue, { |
88 | | - toValue: 0, |
89 | | - easing: RX.Animated.Easing.OutBack(), |
90 | | - duration: 500 |
91 | | - } |
| 31 | + render() { |
| 32 | + return ( |
| 33 | + <RX.Navigator |
| 34 | + ref={ this._onNavigatorRef } |
| 35 | + renderScene={ this._renderScene } |
| 36 | + cardStyle={ styles.navCardStyle } |
| 37 | + /> |
92 | 38 | ); |
93 | | - |
94 | | - animation.start(); |
95 | | - |
96 | | - this._startProgressIndicator(); |
97 | 39 | } |
98 | 40 |
|
99 | | - componentWillUnmount() { |
100 | | - this._stopProgressIndicator(); |
| 41 | + private _onNavigatorRef = (navigator: RX.Navigator) => { |
| 42 | + this._navigator = navigator; |
101 | 43 | } |
102 | 44 |
|
103 | | - render(): JSX.Element | null { |
104 | | - return ( |
105 | | - <RX.ScrollView style={ styles.scroll }> |
106 | | - <RX.View style={ styles.container }> |
107 | | - <RX.Animated.Text style={ [styles.helloWorld, this._animatedStyle] }> |
108 | | - Hello World |
109 | | - </RX.Animated.Text> |
110 | | - <RX.Text style={ styles.welcome }> |
111 | | - Welcome to ReactXP |
112 | | - </RX.Text> |
113 | | - <RX.Text style={ styles.instructions }> |
114 | | - Edit App.tsx to get started |
115 | | - </RX.Text> |
116 | | - <RX.Link style={ styles.docLink } url={ 'https://microsoft.github.io/reactxp/docs' }> |
117 | | - View ReactXP documentation |
118 | | - </RX.Link> |
119 | | - |
120 | | - <RX.Text style={ styles.titleText }> |
121 | | - Here is a simple control built using ReactXP |
122 | | - </RX.Text> |
123 | | - <ToggleSwitch |
124 | | - value={ this.state.toggleValue } |
125 | | - onChange={ this._onChangeToggle } |
126 | | - /> |
127 | | - |
128 | | - <RX.Text style={ styles.titleText }> |
129 | | - Here is an SVG image using the ImageSvg extension |
130 | | - </RX.Text> |
131 | | - <ProgressIndicator |
132 | | - style={ styles.progressMargin } |
133 | | - progress={ this.state.progressValue } |
134 | | - fillColor={ '#ddd' } |
135 | | - size={ 32 } |
136 | | - /> |
137 | | - |
138 | | - <RX.Text style={ [styles.titleText, styles.videoTitleText] }> |
139 | | - Here is a video using the Video extension |
140 | | - </RX.Text> |
141 | | - <RXVideo |
142 | | - ref='video' |
143 | | - style={ styles.video } |
144 | | - source={ 'https://www.w3schools.com/html/mov_bbb.mp4' } |
145 | | - loop={ true } |
146 | | - onCanPlay={ this._playVideo } |
147 | | - /> |
148 | | - </RX.View> |
149 | | - </RX.ScrollView> |
150 | | - |
151 | | - ); |
152 | | - } |
| 45 | + private _renderScene = (navigatorRoute: RX.Types.NavigatorRoute) => { |
| 46 | + switch (navigatorRoute.routeId) { |
| 47 | + case NavigationRouteId.MainPanel: |
| 48 | + return <MainPanel onPressNavigate={ this._onPressNavigate } /> |
153 | 49 |
|
154 | | - private _playVideo = () => { |
155 | | - const video = this.refs['video'] as RXVideo; |
156 | | - if (video) { |
157 | | - video.mute(true); |
158 | | - video.play(); |
| 50 | + case NavigationRouteId.SecondPanel: |
| 51 | + return <SecondPanel onNavigateBack={ this._onPressBack } /> |
159 | 52 | } |
160 | | - } |
161 | 53 |
|
162 | | - private _startProgressIndicator() { |
163 | | - this._progressTimerToken = window.setInterval(() => { |
164 | | - const newProgressValue = (this.state.progressValue + 0.02) % 1; |
165 | | - this.setState({ progressValue: newProgressValue }); |
166 | | - }, 1000 / 15); |
| 54 | + return null; |
167 | 55 | } |
168 | 56 |
|
169 | | - private _stopProgressIndicator() { |
170 | | - if (this._progressTimerToken) { |
171 | | - window.clearInterval(this._progressTimerToken); |
172 | | - this._progressTimerToken = undefined; |
173 | | - } |
| 57 | + private _onPressNavigate = () => { |
| 58 | + this._navigator.push({ |
| 59 | + routeId: NavigationRouteId.SecondPanel, |
| 60 | + sceneConfigType: RX.Types.NavigatorSceneConfigType.FloatFromRight, |
| 61 | + customSceneConfig: { |
| 62 | + hideShadow: true |
| 63 | + } |
| 64 | + }); |
174 | 65 | } |
175 | 66 |
|
176 | | - // Note that we define this as a variable rather than a normal method. Using this |
177 | | - // method, we prebind the method to this component instance. This prebinding ensures |
178 | | - // that each time we pass the variable as a prop in the render function, it will |
179 | | - // not change. We want to avoid unnecessary prop changes because this will trigger |
180 | | - // extra work within React's virtual DOM diffing mechanism. |
181 | | - private _onChangeToggle = (newValue: boolean) => { |
182 | | - this.setState({ toggleValue: newValue }); |
| 67 | + private _onPressBack = () => { |
| 68 | + this._navigator.pop(); |
183 | 69 | } |
184 | 70 | } |
185 | 71 |
|
|
0 commit comments