Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 04d5d11

Browse files
authored
refactor: create Android and iOS specific NgModule (#85)
1 parent a36f194 commit 04d5d11

Some content is hidden

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

82 files changed

+286
-170
lines changed

doc/pages/bootstrap.jade

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ block content
1515
bootstrapReactNative('myApp', MyAppModule);
1616
```
1717

18-
The main module must import the `ReactNativeModule`:
18+
The main module must import `ReactNativeAndroidModule` or `ReactNativeiOSModule` depending on the platform targetted:
1919
```
2020
@NgModule({
2121
declarations: [...],
22-
imports: [ReactNativeModule, CommonModule],
22+
imports: [ReactNativeAndroidModule, CommonModule],
2323
bootstrap: [...]
2424
})
2525
export class MyAppModule {}

doc/pages/http.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ block content
1616
```
1717
@NgModule({
1818
declarations: [...],
19-
imports: [ReactNativeModule, CommonModule, ReactNativeHttpModule],
19+
imports: [ReactNativeAndroidModule, CommonModule, ReactNativeHttpModule],
2020
bootstrap: [...]
2121
})
2222
export class MyAppModule {}

doc/pages/router.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ block content
2121

2222
@NgModule({
2323
declarations: [Example, CompA, CompB, ...],
24-
imports: [ReactNativeModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
24+
imports: [ReactNativeAndroidModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
2525
bootstrap: [Example]
2626
})
2727
export class MyAppModule {}

doc/parser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ function getFiles(dir, files_){
137137
if (fs.statSync(name).isDirectory()){
138138
getFiles(name, files_);
139139
} else {
140-
files_.push(name);
140+
if (name.indexOf('/_') == -1 && name.indexOf('module') == -1) {
141+
files_.push(name);
142+
}
141143
}
142144
}
143145
return files_;

gulpfile.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ var PATHS = {
2929
tmp: 'dist/tmp',
3030
publish: 'dist/publish',
3131
modules: [
32-
'node_modules/@angular/**/*',
32+
'node_modules/@angular/common/**/*',
33+
'node_modules/@angular/compiler/**/*',
34+
'node_modules/@angular/core/**/*',
35+
'node_modules/@angular/http/**/*',
36+
'node_modules/@angular/platform-browser/**/*',
37+
'node_modules/@angular/platform-browser-dynamic/**/*',
38+
'node_modules/@angular/platform-server/**/*',
39+
'node_modules/@angular/router/**/*',
3340
'node_modules/hammerjs/**/*',
3441
'node_modules/reflect-metadata/**/*',
3542
'node_modules/rxjs/**/*',
@@ -53,7 +60,7 @@ gulp.task('!postcreate', ['!create'], function() {
5360
.pipe(gulp.dest(PATHS.app + '/' + APP_NAME + '/android/app/src/main/'));
5461

5562
});
56-
gulp.task('init', ['!postcreate'], function() {
63+
gulp.task('init', function() {
5764
var copier = require('./tools/copy-dependencies');
5865
return copier.doCopy(PATHS.modules, PATHS.app + '/' + APP_NAME + '/node_modules');
5966
});
@@ -259,7 +266,7 @@ gulp.task('clean.code', function (done) {
259266
});
260267

261268
function ts2js(path, dest, toSystem, withDeclaration) {
262-
var tsResult = gulp.src(path.concat(['typings/index.d.ts', 'src/angular2-react-native.d.ts']), {base: './'})
269+
var tsResult = gulp.src(path.concat(['typings/index.d.ts', 'src/angular2-react-native.d.ts', 'src/angular2-react-native-android.d.ts', 'src/angular2-react-native-ios.d.ts']), {base: './'})
263270
.pipe(typescript({
264271
noImplicitAny: true,
265272
module: toSystem ? 'system' : 'commonjs',
@@ -337,6 +344,8 @@ function customReporter() {
337344
if (error.relativeFilename && error.message.indexOf(`Module '"react-native"' has no exported member`) == -1 &&
338345
error.message.indexOf(`Module ''angular2-react-native'' has no exported member`) == -1 &&
339346
error.message.indexOf(`src\\angular2-react-native.d.ts`) == -1 &&
347+
error.message.indexOf(`src\\angular2-react-native-android.d.ts`) == -1 &&
348+
error.message.indexOf(`src\\angular2-react-native-ios.d.ts`) == -1 &&
340349
error.message.indexOf(`does not exist on type 'Global'.`) == -1) {
341350
console.error(error.message);
342351
}

sample/samples/android/kitchensink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Component, ElementRef, ViewChild} from '@angular/core';
22
import {Router, NavigationEnd} from '@angular/router';
33
import {LocationStrategy} from '@angular/common';
44
import {StyleSheet, BackAndroid, Alert, NativeModules, processColor} from 'react-native';
5-
import {DrawerLayout, Toolbar} from 'angular2-react-native';
5+
import {DrawerLayout, Toolbar} from 'angular2-react-native/android';
66

77
import {TodoMVC} from "./../common/todomvc";
88

sample/samples/android/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {NgModule} from '@angular/core';
22
import {CommonModule} from '@angular/common';
33
import {Routes} from '@angular/router';
4-
import {ReactNativeModule, ReactNativeRouterModule, ReactNativeHttpModule} from 'angular2-react-native';
4+
import {ReactNativeAndroidModule, ReactNativeRouterModule, ReactNativeHttpModule} from 'angular2-react-native';
55
import {KitchenSinkApp} from './kitchensink';
66

77
import {HelloApp} from "./hello";
@@ -26,7 +26,7 @@ const appRoutes: Routes = [
2626

2727
@NgModule({
2828
declarations: [KitchenSinkApp, HelloApp, TodoMVC, TodoItem, GesturesApp, WidgetsList, WebViewApp, APIsList, HttpApp, AnimationApp, Ball],
29-
imports: [ReactNativeModule, ReactNativeHttpModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
29+
imports: [ReactNativeAndroidModule, ReactNativeHttpModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
3030
bootstrap: [KitchenSinkApp]
3131
})
3232
export class KitchenSinkModule {}

sample/samples/common/animation.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {Component, Input, Output, ElementRef, EventEmitter, ViewChildren, QueryList} from '@angular/core';
22
import {StyleSheet} from 'react-native';
3-
import {TodoMVC} from "./todomvc";
43

54
@Component({
65
selector: 'ball',

sample/samples/common/http.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {Component, ViewChild} from '@angular/core';
22
import {Http} from '@angular/http';
33
import 'rxjs/add/operator/map';
44

5-
import {TextInput} from 'angular2-react-native';
5+
import {TextInput as TextInputAndroid} from 'angular2-react-native/android';
6+
import {TextInput as TextInputIOS} from 'angular2-react-native/ios';
67

78
@Component({
89
selector: 'http-app',
@@ -13,7 +14,8 @@ import {TextInput} from 'angular2-react-native';
1314
`
1415
})
1516
export class HttpApp {
16-
@ViewChild(TextInput) textInput: TextInput;
17+
@ViewChild(TextInputAndroid) textInputAndroid: TextInputAndroid;
18+
@ViewChild(TextInputIOS) textInputIOS: TextInputIOS;
1719
pages: Array<any> = [];
1820
constructor(private http: Http) {}
1921

@@ -28,7 +30,8 @@ export class HttpApp {
2830
this.pages.push(raw[key].title);
2931
}
3032
});
31-
this.textInput.blurTextInput();
33+
if (this.textInputAndroid) this.textInputAndroid.blurTextInput();
34+
if (this.textInputIOS) this.textInputIOS.blurTextInput();
3235
}
3336

3437
}

sample/samples/common/todomvc.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Component, Input, Output, EventEmitter, ViewChild} from '@angular/core';
22
import {StyleSheet, AsyncStorage} from 'react-native';
3-
import {TextInput} from 'angular2-react-native';
3+
import {TextInput as TextInputAndroid} from 'angular2-react-native/android';
4+
import {TextInput as TextInputIOS} from 'angular2-react-native/ios';
45

56
class Palette {
67
static background: string = '#005eb8';
@@ -31,7 +32,8 @@ class Todo {
3132
`
3233
})
3334
export class TodoItem {
34-
@ViewChild(TextInput) textInput: TextInput;
35+
@ViewChild(TextInputAndroid) textInputAndroid: TextInputAndroid;
36+
@ViewChild(TextInputIOS) textInputIOS: TextInputIOS;
3537
styles: any;
3638
@Input() item: Todo;
3739
@Output() toggled: EventEmitter<number> = new EventEmitter();
@@ -55,7 +57,8 @@ export class TodoItem {
5557
}
5658

5759
stopEdit(text: string) {
58-
this.textInput.blurTextInput();
60+
if (this.textInputAndroid) this.textInputAndroid.blurTextInput();
61+
if (this.textInputIOS) this.textInputIOS.blurTextInput();
5962
if (text && text.length > 0) {
6063
this.item.value = text;
6164
}
@@ -147,7 +150,8 @@ export class TodoItem {
147150
`
148151
})
149152
export class TodoMVC {
150-
@ViewChild(TextInput) textInput: TextInput;
153+
@ViewChild(TextInputAndroid) textInputAndroid: TextInputAndroid;
154+
@ViewChild(TextInputIOS) textInputIOS: TextInputIOS;
151155
styles: any;
152156
todos: Array<Todo> = [];
153157
filteredTodos: Array<Todo> = [];
@@ -165,8 +169,14 @@ export class TodoMVC {
165169
this.leftCount++;
166170
}
167171
this.filterTodos();
168-
this.textInput.value = '';
169-
this.textInput.blurTextInput();
172+
if (this.textInputAndroid) {
173+
this.textInputAndroid.value = '';
174+
this.textInputAndroid.blurTextInput();
175+
}
176+
if (this.textInputIOS) {
177+
this.textInputIOS.value = '';
178+
this.textInputIOS.blurTextInput();
179+
}
170180
}
171181

172182
deleteTodo(todo: Todo) {

sample/samples/common/webview.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Component, ElementRef, ViewChild} from '@angular/core';
22
import {StyleSheet} from 'react-native';
3-
import {WebView} from 'angular2-react-native';
3+
import {WebView as WebViewAndroid} from 'angular2-react-native/android';
4+
import {WebView as WebViewIOS} from 'angular2-react-native/ios';
45

56
@Component({
67
selector: 'webview-app',
@@ -19,7 +20,8 @@ import {WebView} from 'angular2-react-native';
1920
`
2021
})
2122
export class WebViewApp {
22-
@ViewChild(WebView) webView: WebView;
23+
@ViewChild(WebViewAndroid) webViewAndroid: WebViewAndroid;
24+
@ViewChild(WebViewIOS) webViewIOS: WebViewIOS;
2325
styles: any;
2426
_el : any = null;
2527
constructor(el: ElementRef) {
@@ -40,11 +42,13 @@ export class WebViewApp {
4042
}
4143

4244
goBack() {
43-
this.webView.goBack();
45+
if (this.webViewAndroid) this.webViewAndroid.goBack();
46+
if (this.webViewIOS) this.webViewIOS.goBack();
4447
}
4548

4649
goForward() {
47-
this.webView.goForward();
50+
if (this.webViewAndroid) this.webViewAndroid.goForward();
51+
if (this.webViewIOS) this.webViewIOS.goForward();
4852
}
4953
}
5054

sample/samples/ios/kitchensink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Component, ViewChild} from '@angular/core';
22
import {ActionSheetIOS} from 'react-native';
3-
import {Navigator} from 'angular2-react-native';
3+
import {Navigator} from 'angular2-react-native/ios';
44
import {TodoMVC} from "../common/todomvc";
55

66
@Component({

sample/samples/ios/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {NgModule} from '@angular/core';
22
import {CommonModule} from '@angular/common';
33
import {Routes} from '@angular/router';
4-
import {ReactNativeModule, ReactNativeRouterModule, ReactNativeHttpModule} from 'angular2-react-native';
4+
import {ReactNativeiOSModule, ReactNativeRouterModule, ReactNativeHttpModule} from 'angular2-react-native';
55
import {KitchenSinkApp} from './kitchensink';
66

77
import {HelloApp} from "./hello";
@@ -26,7 +26,7 @@ const appRoutes: Routes = [
2626

2727
@NgModule({
2828
declarations: [KitchenSinkApp, HelloApp, TodoMVC, TodoItem, GesturesApp, WidgetsList, WebViewApp, APIsApp, HttpApp, AnimationApp, Ball],
29-
imports: [ReactNativeModule, ReactNativeHttpModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
29+
imports: [ReactNativeiOSModule, ReactNativeHttpModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
3030
bootstrap: [KitchenSinkApp]
3131
})
3232
export class KitchenSinkModule {}

src/android.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export {ActivityIndicator} from './components/android/_activity_indicator';
2+
export {Image} from './components/android/_image';
3+
export {Picker} from './components/android/_picker';
4+
export {RefreshControl} from './components/android/_refresh_control';
5+
export {ScrollView} from './components/android/_scrollview';
6+
export {Slider} from './components/android/_slider';
7+
export {Switch} from './components/android/_switch';
8+
export {Text} from './components/android/_text';
9+
export {TextInput} from './components/android/_textinput';
10+
export {View} from './components/android/_view';
11+
export {WebView} from './components/android/_webview';
12+
13+
export {DrawerLayout} from './components/android/drawer_layout';
14+
export {PagerLayout} from './components/android/pager_layout';
15+
export {ProgressBar} from './components/android/progress_bar';
16+
export {Toolbar} from './components/android/toolbar';
17+
18+
19+
20+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module 'angular2-react-native/android' {
2+
3+
export * from './android';
4+
}
5+

src/angular2-react-native-ios.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module 'angular2-react-native/ios' {
2+
3+
export * from './ios';
4+
}
5+

src/angular2-react-native.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ declare module 'angular2-react-native' {
22

33
export * from './index';
44
}
5+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './../common/activity_indicator';

src/components/android/_image.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './../common/image';

src/components/android/_picker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './../common/picker';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './../common/refresh_control';

src/components/android/_scrollview.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './../common/scrollview';

src/components/android/_slider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './../common/slider';

src/components/android/_switch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './../common/switch';

src/components/android/_text.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './../common/text';

src/components/android/_textinput.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './../common/textinput';

src/components/android/_view.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './../common/view';

src/components/android/_webview.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './../common/webview';

src/components/android/drawer_layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, Inject, ElementRef, Output, EventEmitter} from "@angular/core";
2-
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./../component";
2+
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "../common/component";
33
import {Node} from "../../renderer/node";
44
import {REACT_NATIVE_WRAPPER} from "./../../renderer/renderer";
55
import {ReactNativeWrapper} from "../../wrapper/wrapper";

src/components/android/pager_layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, Inject, ElementRef, Output, EventEmitter, OnInit} from "@angular/core";
2-
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./../component";
2+
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "../common/component";
33
import {Node} from "../../renderer/node";
44
import {REACT_NATIVE_WRAPPER} from "./../../renderer/renderer";
55
import {ReactNativeWrapper} from "../../wrapper/wrapper";

src/components/android/progress_bar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, Inject} from "@angular/core";
2-
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./../component";
2+
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "../common/component";
33
import {REACT_NATIVE_WRAPPER} from "./../../renderer/renderer";
44
import {ReactNativeWrapper} from "../../wrapper/wrapper";
55

src/components/android/toolbar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, Inject, Output, EventEmitter} from "@angular/core";
2-
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./../component";
2+
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "../common/component";
33
import {REACT_NATIVE_WRAPPER} from "./../../renderer/renderer";
44
import {ReactNativeWrapper} from "../../wrapper/wrapper";
55

src/components/activity_indicator.ts renamed to src/components/common/activity_indicator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Component, Inject} from "@angular/core";
22
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./component";
3-
import {REACT_NATIVE_WRAPPER} from "../renderer/renderer";
4-
import {ReactNativeWrapper, isAndroid} from "../wrapper/wrapper";
3+
import {REACT_NATIVE_WRAPPER} from "../../renderer/renderer";
4+
import {ReactNativeWrapper, isAndroid} from "../../wrapper/wrapper";
55

66
/**
77
* A component for displaying an activity indicator.

src/components/component.ts renamed to src/components/common/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ReactNativeWrapper, isAndroid} from "./../wrapper/wrapper";
1+
import {ReactNativeWrapper, isAndroid} from "../../wrapper/wrapper";
22

33
var ANDROID_INPUTS: Array<string> = ['collapsable', 'accessibilityLiveRegion', 'accessibilityComponentType',
44
'importantForAccessibility', 'needsOffscreenAlphaCompositing', 'renderToHardwareTextureAndroid ', 'nativeBackgroundAndroid'];

src/components/image.ts renamed to src/components/common/image.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Component, Inject, Output, EventEmitter} from "@angular/core";
22
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./component";
3-
import {REACT_NATIVE_WRAPPER} from "./../renderer/renderer";
4-
import {ReactNativeWrapper, isAndroid} from "../wrapper/wrapper";
3+
import {REACT_NATIVE_WRAPPER} from "../../renderer/renderer";
4+
import {ReactNativeWrapper, isAndroid} from "../../wrapper/wrapper";
55

66
var ANDROID_INPUTS: Array<string> = ['fadeDuration', 'loadingIndicatorSrc', 'progressiveRenderingEnabled', 'shouldNotifyLoadEvents'];
77
var IOS_INPUTS: Array<string> = ['blurRadius', 'capInsets', 'defaultSource'];

0 commit comments

Comments
 (0)