Skip to content

Commit fab6efe

Browse files
authored
Merge pull request #36 from bradmartin/angular-reactiveforms-support
feat(Angular): FormsModule + ReactiveFormsModule support via TNSCheckBoxModule
2 parents b265286 + 2e6ff06 commit fab6efe

File tree

87 files changed

+1017
-28
lines changed

Some content is hidden

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

87 files changed

+1017
-28
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ demo/*.d.ts
99
demo/platforms
1010
demo/node_modules
1111
demo/.vscode
12+
demo-ng/app/*.js
13+
demo-ng/*.d.ts
14+
demo-ng/platforms
15+
demo-ng/node_modules
16+
demo/.vscode
17+
demo-ng/.vscode
1218
node_modules
1319
.vscode/
1420
.idea/

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
demo/
2+
demo-ng/
23
screens/
34
app/
45
.vscode/

README.md

Lines changed: 8 additions & 3 deletions

angular/index.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Directive, ElementRef, HostListener, Inject, NgModule, forwardRef } from "@angular/core";
2+
import { FormsModule, NG_VALUE_ACCESSOR } from "@angular/forms";
3+
import { registerElement } from "nativescript-angular/element-registry";
4+
import { BaseValueAccessor } from "nativescript-angular/value-accessors/base-value-accessor";
5+
import { convertToInt } from "nativescript-angular/common/utils";
6+
import { View } from "tns-core-modules/ui/core/view";
7+
8+
registerElement("CheckBox", () => require("../checkbox").CheckBox);
9+
10+
const CHECKED_VALUE_ACCESSOR = {
11+
provide: NG_VALUE_ACCESSOR,
12+
useExisting: forwardRef(() => CheckedValueAccessor), multi: true
13+
};
14+
15+
export type CheckableView = {checked: boolean} & View;
16+
17+
/**
18+
* The accessor for setting checked property and listening to changes that is used by the
19+
* {@link NgModel} directives.
20+
*
21+
* ### Example
22+
* ```
23+
* <CheckBox [(ngModel)]="model.test">
24+
* ```
25+
*/
26+
@Directive({
27+
selector: "CheckBox[ngModel], CheckBox[formControlName], CheckBox[ngModel], CheckBox[formControlName], check-box[ngModel], check-box[formControlName]",
28+
providers: [CHECKED_VALUE_ACCESSOR]
29+
})
30+
export class CheckedValueAccessor extends BaseValueAccessor<CheckableView> {
31+
32+
constructor(@Inject(ElementRef) elementRef: ElementRef) {
33+
super(elementRef.nativeElement);
34+
}
35+
36+
@HostListener("checkedChange", ["$event"])
37+
public checkedChangeListener(event: any) {
38+
this.onChange(event.value);
39+
}
40+
41+
public onTouched = () => { };
42+
43+
public writeValue(value: any): void {
44+
this.view.checked = value;
45+
}
46+
47+
public registerOnTouched(fn: () => void): void { this.onTouched = fn; }
48+
}
49+
50+
@NgModule({
51+
declarations: [
52+
CheckedValueAccessor
53+
],
54+
providers: [],
55+
imports: [
56+
FormsModule
57+
],
58+
exports: [
59+
FormsModule,
60+
CheckedValueAccessor
61+
]
62+
})
63+
export class TNSCheckBoxModule {
64+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="__PACKAGE__"
4+
android:versionCode="1"
5+
android:versionName="1.0">
6+
7+
<supports-screens
8+
android:smallScreens="true"
9+
android:normalScreens="true"
10+
android:largeScreens="true"
11+
android:xlargeScreens="true"/>
12+
13+
<uses-sdk
14+
android:minSdkVersion="17"
15+
android:targetSdkVersion="__APILEVEL__"/>
16+
17+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
18+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
19+
<uses-permission android:name="android.permission.INTERNET"/>
20+
21+
<application
22+
android:name="com.tns.NativeScriptApplication"
23+
android:allowBackup="true"
24+
android:icon="@drawable/icon"
25+
android:label="@string/app_name"
26+
android:theme="@style/AppTheme">
27+
28+
<activity
29+
android:name="com.tns.NativeScriptActivity"
30+
android:label="@string/title_activity_kimera"
31+
android:configChanges="keyboardHidden|orientation|screenSize"
32+
android:theme="@style/LaunchScreenTheme">
33+
34+
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
35+
36+
<intent-filter>
37+
<action android:name="android.intent.action.MAIN" />
38+
<category android:name="android.intent.category.LAUNCHER" />
39+
</intent-filter>
40+
</activity>
41+
<activity android:name="com.tns.ErrorReportActivity"/>
42+
</application>
43+
</manifest>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Add your native dependencies here:
2+
3+
// Uncomment to add recyclerview-v7 dependency
4+
//dependencies {
5+
// compile 'com.android.support:recyclerview-v7:+'
6+
//}
7+
8+
android {
9+
defaultConfig {
10+
generatedDensities = []
11+
applicationId = "__PACKAGE__"
12+
}
13+
aaptOptions {
14+
additionalParameters "--no-version-vectors"
15+
}
16+
}
3.42 KB
10.7 KB
32.4 KB
1.31 KB

0 commit comments

Comments
 (0)