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

refactor: create Android and iOS specific NgModule #85

Merged
merged 1 commit into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/pages/bootstrap.jade
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ block content
bootstrapReactNative('myApp', MyAppModule);
```

The main module must import the `ReactNativeModule`:
The main module must import `ReactNativeAndroidModule` or `ReactNativeiOSModule` depending on the platform targetted:
```
@NgModule({
declarations: [...],
imports: [ReactNativeModule, CommonModule],
imports: [ReactNativeAndroidModule, CommonModule],
bootstrap: [...]
})
export class MyAppModule {}
Expand Down
2 changes: 1 addition & 1 deletion doc/pages/http.jade
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ block content
```
@NgModule({
declarations: [...],
imports: [ReactNativeModule, CommonModule, ReactNativeHttpModule],
imports: [ReactNativeAndroidModule, CommonModule, ReactNativeHttpModule],
bootstrap: [...]
})
export class MyAppModule {}
Expand Down
2 changes: 1 addition & 1 deletion doc/pages/router.jade
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ block content

@NgModule({
declarations: [Example, CompA, CompB, ...],
imports: [ReactNativeModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
imports: [ReactNativeAndroidModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
bootstrap: [Example]
})
export class MyAppModule {}
Expand Down
4 changes: 3 additions & 1 deletion doc/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ function getFiles(dir, files_){
if (fs.statSync(name).isDirectory()){
getFiles(name, files_);
} else {
files_.push(name);
if (name.indexOf('/_') == -1 && name.indexOf('module') == -1) {
files_.push(name);
}
}
}
return files_;
Expand Down
15 changes: 12 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ var PATHS = {
tmp: 'dist/tmp',
publish: 'dist/publish',
modules: [
'node_modules/@angular/**/*',
'node_modules/@angular/common/**/*',
'node_modules/@angular/compiler/**/*',
'node_modules/@angular/core/**/*',
'node_modules/@angular/http/**/*',
'node_modules/@angular/platform-browser/**/*',
'node_modules/@angular/platform-browser-dynamic/**/*',
'node_modules/@angular/platform-server/**/*',
'node_modules/@angular/router/**/*',
'node_modules/hammerjs/**/*',
'node_modules/reflect-metadata/**/*',
'node_modules/rxjs/**/*',
Expand All @@ -53,7 +60,7 @@ gulp.task('!postcreate', ['!create'], function() {
.pipe(gulp.dest(PATHS.app + '/' + APP_NAME + '/android/app/src/main/'));

});
gulp.task('init', ['!postcreate'], function() {
gulp.task('init', function() {
var copier = require('./tools/copy-dependencies');
return copier.doCopy(PATHS.modules, PATHS.app + '/' + APP_NAME + '/node_modules');
});
Expand Down Expand Up @@ -259,7 +266,7 @@ gulp.task('clean.code', function (done) {
});

function ts2js(path, dest, toSystem, withDeclaration) {
var tsResult = gulp.src(path.concat(['typings/index.d.ts', 'src/angular2-react-native.d.ts']), {base: './'})
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: './'})
.pipe(typescript({
noImplicitAny: true,
module: toSystem ? 'system' : 'commonjs',
Expand Down Expand Up @@ -337,6 +344,8 @@ function customReporter() {
if (error.relativeFilename && error.message.indexOf(`Module '"react-native"' has no exported member`) == -1 &&
error.message.indexOf(`Module ''angular2-react-native'' has no exported member`) == -1 &&
error.message.indexOf(`src\\angular2-react-native.d.ts`) == -1 &&
error.message.indexOf(`src\\angular2-react-native-android.d.ts`) == -1 &&
error.message.indexOf(`src\\angular2-react-native-ios.d.ts`) == -1 &&
error.message.indexOf(`does not exist on type 'Global'.`) == -1) {
console.error(error.message);
}
Expand Down
2 changes: 1 addition & 1 deletion sample/samples/android/kitchensink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Component, ElementRef, ViewChild} from '@angular/core';
import {Router, NavigationEnd} from '@angular/router';
import {LocationStrategy} from '@angular/common';
import {StyleSheet, BackAndroid, Alert, NativeModules, processColor} from 'react-native';
import {DrawerLayout, Toolbar} from 'angular2-react-native';
import {DrawerLayout, Toolbar} from 'angular2-react-native/android';

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

Expand Down
4 changes: 2 additions & 2 deletions sample/samples/android/module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {Routes} from '@angular/router';
import {ReactNativeModule, ReactNativeRouterModule, ReactNativeHttpModule} from 'angular2-react-native';
import {ReactNativeAndroidModule, ReactNativeRouterModule, ReactNativeHttpModule} from 'angular2-react-native';
import {KitchenSinkApp} from './kitchensink';

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

@NgModule({
declarations: [KitchenSinkApp, HelloApp, TodoMVC, TodoItem, GesturesApp, WidgetsList, WebViewApp, APIsList, HttpApp, AnimationApp, Ball],
imports: [ReactNativeModule, ReactNativeHttpModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
imports: [ReactNativeAndroidModule, ReactNativeHttpModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
bootstrap: [KitchenSinkApp]
})
export class KitchenSinkModule {}
1 change: 0 additions & 1 deletion sample/samples/common/animation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Component, Input, Output, ElementRef, EventEmitter, ViewChildren, QueryList} from '@angular/core';
import {StyleSheet} from 'react-native';
import {TodoMVC} from "./todomvc";

@Component({
selector: 'ball',
Expand Down
9 changes: 6 additions & 3 deletions sample/samples/common/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {Component, ViewChild} from '@angular/core';
import {Http} from '@angular/http';
import 'rxjs/add/operator/map';

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

@Component({
selector: 'http-app',
Expand All @@ -13,7 +14,8 @@ import {TextInput} from 'angular2-react-native';
`
})
export class HttpApp {
@ViewChild(TextInput) textInput: TextInput;
@ViewChild(TextInputAndroid) textInputAndroid: TextInputAndroid;
@ViewChild(TextInputIOS) textInputIOS: TextInputIOS;
pages: Array<any> = [];
constructor(private http: Http) {}

Expand All @@ -28,7 +30,8 @@ export class HttpApp {
this.pages.push(raw[key].title);
}
});
this.textInput.blurTextInput();
if (this.textInputAndroid) this.textInputAndroid.blurTextInput();
if (this.textInputIOS) this.textInputIOS.blurTextInput();
}

}
Expand Down
22 changes: 16 additions & 6 deletions sample/samples/common/todomvc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Component, Input, Output, EventEmitter, ViewChild} from '@angular/core';
import {StyleSheet, AsyncStorage} from 'react-native';
import {TextInput} from 'angular2-react-native';
import {TextInput as TextInputAndroid} from 'angular2-react-native/android';
import {TextInput as TextInputIOS} from 'angular2-react-native/ios';

class Palette {
static background: string = '#005eb8';
Expand Down Expand Up @@ -31,7 +32,8 @@ class Todo {
`
})
export class TodoItem {
@ViewChild(TextInput) textInput: TextInput;
@ViewChild(TextInputAndroid) textInputAndroid: TextInputAndroid;
@ViewChild(TextInputIOS) textInputIOS: TextInputIOS;
styles: any;
@Input() item: Todo;
@Output() toggled: EventEmitter<number> = new EventEmitter();
Expand All @@ -55,7 +57,8 @@ export class TodoItem {
}

stopEdit(text: string) {
this.textInput.blurTextInput();
if (this.textInputAndroid) this.textInputAndroid.blurTextInput();
if (this.textInputIOS) this.textInputIOS.blurTextInput();
if (text && text.length > 0) {
this.item.value = text;
}
Expand Down Expand Up @@ -147,7 +150,8 @@ export class TodoItem {
`
})
export class TodoMVC {
@ViewChild(TextInput) textInput: TextInput;
@ViewChild(TextInputAndroid) textInputAndroid: TextInputAndroid;
@ViewChild(TextInputIOS) textInputIOS: TextInputIOS;
styles: any;
todos: Array<Todo> = [];
filteredTodos: Array<Todo> = [];
Expand All @@ -165,8 +169,14 @@ export class TodoMVC {
this.leftCount++;
}
this.filterTodos();
this.textInput.value = '';
this.textInput.blurTextInput();
if (this.textInputAndroid) {
this.textInputAndroid.value = '';
this.textInputAndroid.blurTextInput();
}
if (this.textInputIOS) {
this.textInputIOS.value = '';
this.textInputIOS.blurTextInput();
}
}

deleteTodo(todo: Todo) {
Expand Down
12 changes: 8 additions & 4 deletions sample/samples/common/webview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Component, ElementRef, ViewChild} from '@angular/core';
import {StyleSheet} from 'react-native';
import {WebView} from 'angular2-react-native';
import {WebView as WebViewAndroid} from 'angular2-react-native/android';
import {WebView as WebViewIOS} from 'angular2-react-native/ios';

@Component({
selector: 'webview-app',
Expand All @@ -19,7 +20,8 @@ import {WebView} from 'angular2-react-native';
`
})
export class WebViewApp {
@ViewChild(WebView) webView: WebView;
@ViewChild(WebViewAndroid) webViewAndroid: WebViewAndroid;
@ViewChild(WebViewIOS) webViewIOS: WebViewIOS;
styles: any;
_el : any = null;
constructor(el: ElementRef) {
Expand All @@ -40,11 +42,13 @@ export class WebViewApp {
}

goBack() {
this.webView.goBack();
if (this.webViewAndroid) this.webViewAndroid.goBack();
if (this.webViewIOS) this.webViewIOS.goBack();
}

goForward() {
this.webView.goForward();
if (this.webViewAndroid) this.webViewAndroid.goForward();
if (this.webViewIOS) this.webViewIOS.goForward();
}
}

2 changes: 1 addition & 1 deletion sample/samples/ios/kitchensink.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component, ViewChild} from '@angular/core';
import {ActionSheetIOS} from 'react-native';
import {Navigator} from 'angular2-react-native';
import {Navigator} from 'angular2-react-native/ios';
import {TodoMVC} from "../common/todomvc";

@Component({
Expand Down
4 changes: 2 additions & 2 deletions sample/samples/ios/module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {Routes} from '@angular/router';
import {ReactNativeModule, ReactNativeRouterModule, ReactNativeHttpModule} from 'angular2-react-native';
import {ReactNativeiOSModule, ReactNativeRouterModule, ReactNativeHttpModule} from 'angular2-react-native';
import {KitchenSinkApp} from './kitchensink';

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

@NgModule({
declarations: [KitchenSinkApp, HelloApp, TodoMVC, TodoItem, GesturesApp, WidgetsList, WebViewApp, APIsApp, HttpApp, AnimationApp, Ball],
imports: [ReactNativeModule, ReactNativeHttpModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
imports: [ReactNativeiOSModule, ReactNativeHttpModule, CommonModule, ReactNativeRouterModule.forRoot(appRoutes)],
bootstrap: [KitchenSinkApp]
})
export class KitchenSinkModule {}
20 changes: 20 additions & 0 deletions src/android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export {ActivityIndicator} from './components/android/_activity_indicator';
export {Image} from './components/android/_image';
export {Picker} from './components/android/_picker';
export {RefreshControl} from './components/android/_refresh_control';
export {ScrollView} from './components/android/_scrollview';
export {Slider} from './components/android/_slider';
export {Switch} from './components/android/_switch';
export {Text} from './components/android/_text';
export {TextInput} from './components/android/_textinput';
export {View} from './components/android/_view';
export {WebView} from './components/android/_webview';

export {DrawerLayout} from './components/android/drawer_layout';
export {PagerLayout} from './components/android/pager_layout';
export {ProgressBar} from './components/android/progress_bar';
export {Toolbar} from './components/android/toolbar';




5 changes: 5 additions & 0 deletions src/angular2-react-native-android.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'angular2-react-native/android' {

export * from './android';
}

5 changes: 5 additions & 0 deletions src/angular2-react-native-ios.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'angular2-react-native/ios' {

export * from './ios';
}

1 change: 1 addition & 0 deletions src/angular2-react-native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ declare module 'angular2-react-native' {

export * from './index';
}

1 change: 1 addition & 0 deletions src/components/android/_activity_indicator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './../common/activity_indicator';
1 change: 1 addition & 0 deletions src/components/android/_image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './../common/image';
1 change: 1 addition & 0 deletions src/components/android/_picker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './../common/picker';
1 change: 1 addition & 0 deletions src/components/android/_refresh_control.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './../common/refresh_control';
1 change: 1 addition & 0 deletions src/components/android/_scrollview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './../common/scrollview';
1 change: 1 addition & 0 deletions src/components/android/_slider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './../common/slider';
1 change: 1 addition & 0 deletions src/components/android/_switch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './../common/switch';
1 change: 1 addition & 0 deletions src/components/android/_text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './../common/text';
1 change: 1 addition & 0 deletions src/components/android/_textinput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './../common/textinput';
1 change: 1 addition & 0 deletions src/components/android/_view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './../common/view';
1 change: 1 addition & 0 deletions src/components/android/_webview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './../common/webview';
2 changes: 1 addition & 1 deletion src/components/android/drawer_layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, Inject, ElementRef, Output, EventEmitter} from "@angular/core";
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./../component";
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "../common/component";
import {Node} from "../../renderer/node";
import {REACT_NATIVE_WRAPPER} from "./../../renderer/renderer";
import {ReactNativeWrapper} from "../../wrapper/wrapper";
Expand Down
2 changes: 1 addition & 1 deletion src/components/android/pager_layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, Inject, ElementRef, Output, EventEmitter, OnInit} from "@angular/core";
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./../component";
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "../common/component";
import {Node} from "../../renderer/node";
import {REACT_NATIVE_WRAPPER} from "./../../renderer/renderer";
import {ReactNativeWrapper} from "../../wrapper/wrapper";
Expand Down
2 changes: 1 addition & 1 deletion src/components/android/progress_bar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, Inject} from "@angular/core";
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./../component";
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "../common/component";
import {REACT_NATIVE_WRAPPER} from "./../../renderer/renderer";
import {ReactNativeWrapper} from "../../wrapper/wrapper";

Expand Down
2 changes: 1 addition & 1 deletion src/components/android/toolbar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, Inject, Output, EventEmitter} from "@angular/core";
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./../component";
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "../common/component";
import {REACT_NATIVE_WRAPPER} from "./../../renderer/renderer";
import {ReactNativeWrapper} from "../../wrapper/wrapper";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Component, Inject} from "@angular/core";
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./component";
import {REACT_NATIVE_WRAPPER} from "../renderer/renderer";
import {ReactNativeWrapper, isAndroid} from "../wrapper/wrapper";
import {REACT_NATIVE_WRAPPER} from "../../renderer/renderer";
import {ReactNativeWrapper, isAndroid} from "../../wrapper/wrapper";

/**
* A component for displaying an activity indicator.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ReactNativeWrapper, isAndroid} from "./../wrapper/wrapper";
import {ReactNativeWrapper, isAndroid} from "../../wrapper/wrapper";

var ANDROID_INPUTS: Array<string> = ['collapsable', 'accessibilityLiveRegion', 'accessibilityComponentType',
'importantForAccessibility', 'needsOffscreenAlphaCompositing', 'renderToHardwareTextureAndroid ', 'nativeBackgroundAndroid'];
Expand Down
4 changes: 2 additions & 2 deletions src/components/image.ts → src/components/common/image.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Component, Inject, Output, EventEmitter} from "@angular/core";
import {HighLevelComponent, GENERIC_INPUTS, GENERIC_BINDINGS} from "./component";
import {REACT_NATIVE_WRAPPER} from "./../renderer/renderer";
import {ReactNativeWrapper, isAndroid} from "../wrapper/wrapper";
import {REACT_NATIVE_WRAPPER} from "../../renderer/renderer";
import {ReactNativeWrapper, isAndroid} from "../../wrapper/wrapper";

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