Skip to content

Commit c821d41

Browse files
Using returnPress event on html attribute (Angular) #31
1 parent 98b0bab commit c821d41

Some content is hidden

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

41 files changed

+211
-539
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.vscode
33
*.js
44
*.log
5+
*.map
56
*.tgz
67
!src/angular/*.js
78
!demo/karma.conf.js

demo/app/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
import * as application from 'application';
2-
application.start({ moduleName: "main-page" });
2+
application.run({ moduleName: "main-page" });

demo/app/main-page.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ export function pageLoaded(args: EventData) {
4444
}
4545
}
4646

47+
export function textChange(args: EventData) {
48+
console.log("textChange");
49+
}
50+
51+
export function returnPress(args: EventData) {
52+
console.log("returnPress");
53+
}
54+
4755
export function onMyTextLoaded(args: EventData) {
4856
args.object.on("textChange", (args: EventData) => {
4957
let numkey = <TextField>args.object;

demo/app/main-page.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<TextField id="defaultPluginKeyboard" maxLength="4" keyboardType="number" row="2" col="1" text="{{ myTextPlugin }}" loaded="onMyTextLoadedPluginCode"/>
1515

1616
<Label row="3" col="0" text="Custom button title (max 4)"/>
17-
<NumKey:NumericKeyboardView maxLength="4" row="3" col="1" returnKeyButtonBackgroundColor="red" returnKeyTitle="OK :)" text="{{ myTextFieldPlugin }}" loaded="onMyTextLoadedPluginView"/>
17+
<NumKey:NumericKeyboardView textChange="textChange" returnPress="returnPress" maxLength="4" row="3" col="1" returnKeyButtonBackgroundColor="red" returnKeyTitle="OK :)" text="{{ myTextFieldPlugin }}" xloaded="onMyTextLoadedPluginView"/>
1818

1919
<Label row="4" col="0" text="No decimals"/>
2020
<NumKey:NumericKeyboardView row="4" col="1" returnKeyButtonBackgroundColor="#333333" noDecimals="true" text="345"/>

demo/app/vendor-platform.android.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require("application");
2+
if (!global["__snapshot"]) {
3+
// In case snapshot generation is enabled these modules will get into the bundle
4+
// but will not be required/evaluated.
5+
// The snapshot webpack plugin will add them to the tns-java-classes.js bundle file.
6+
// This way, they will be evaluated on app start as early as possible.
7+
require("ui/frame");
8+
require("ui/frame/activity");
9+
}

demo/app/vendor-platform.ios.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// There is a bug in angular: https://github.com/angular/angular-cli/pull/8589/files
2+
// Legendary stuff, its webpack plugin pretty much doesn't work with empty TypeScript files in v1.8.3
3+
void 0;

demo/app/vendor.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Snapshot the ~/app.css and the theme
2+
const application = require("application");
3+
require("ui/styling/style-scope");
4+
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/);
5+
global.registerWebpackModules(appCssContext);
6+
application.loadAppCss();
7+
8+
require("./vendor-platform");
9+
10+
require("bundle-entry-points");

demo/karma.conf.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
module.exports = function (config) {
2+
const options = {
3+
4+
// base path that will be used to resolve all patterns (eg. files, exclude)
5+
basePath: '',
6+
7+
8+
// frameworks to use
9+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
10+
frameworks: ['jasmine'],
11+
12+
13+
// list of files / patterns to load in the browser
14+
files: ['app/tests/**/*.*'],
15+
16+
17+
// list of files to exclude
18+
exclude: [
19+
],
20+
21+
22+
// preprocess matching files before serving them to the browser
23+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
24+
preprocessors: {
25+
},
26+
27+
28+
// test results reporter to use
29+
// possible values: 'dots', 'progress'
30+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
31+
reporters: ['progress'],
32+
33+
34+
// web server port
35+
port: 9876,
36+
37+
38+
// enable / disable colors in the output (reporters and logs)
39+
colors: true,
40+
41+
42+
// level of logging
43+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
44+
logLevel: config.LOG_INFO,
45+
46+
47+
// enable / disable watching file and executing tests whenever any file changes
48+
autoWatch: true,
49+
50+
51+
// start these browsers
52+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
53+
browsers: [],
54+
55+
customLaunchers: {
56+
android: {
57+
base: 'NS',
58+
platform: 'android'
59+
},
60+
ios: {
61+
base: 'NS',
62+
platform: 'ios'
63+
},
64+
ios_simulator: {
65+
base: 'NS',
66+
platform: 'ios',
67+
arguments: ['--emulator']
68+
}
69+
},
70+
71+
// Continuous Integration mode
72+
// if true, Karma captures browsers, runs the tests and exits
73+
singleRun: false
74+
};
75+
76+
setWebpackPreprocessor(config, options);
77+
setWebpack(config, options);
78+
79+
config.set(options);
80+
}
81+
82+
function setWebpackPreprocessor(config, options) {
83+
if (config && config.bundle) {
84+
if (!options.preprocessors) {
85+
options.preprocessors = {};
86+
}
87+
88+
options.files.forEach(file => {
89+
if (!options.preprocessors[file]) {
90+
options.preprocessors[file] = [];
91+
}
92+
options.preprocessors[file].push('webpack');
93+
});
94+
}
95+
}
96+
97+
function setWebpack(config, options) {
98+
if (config && config.bundle) {
99+
const env = {};
100+
env[config.platform] = true;
101+
env.sourceMap = config.debugBrk;
102+
options.webpack = require('./webpack.config')(env);
103+
delete options.webpack.entry;
104+
delete options.webpack.output.libraryTarget;
105+
const invalidPluginsForUnitTesting = ["GenerateBundleStarterPlugin", "GenerateNativeScriptEntryPointsPlugin"];
106+
options.webpack.plugins = options.webpack.plugins.filter(p => !invalidPluginsForUnitTesting.includes(p.constructor.name));
107+
}
108+
}

demo/nsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"useLegacyWorkflow": false
3+
}

demo/package.json

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
{
22
"nativescript": {
33
"id": "org.nativescript.demo",
4-
"tns-ios": {
5-
"version": "5.2.0"
6-
},
74
"tns-android": {
8-
"version": "5.2.0"
5+
"version": "6.0.0"
6+
},
7+
"tns-ios": {
8+
"version": "6.0.1"
99
}
1010
},
1111
"dependencies": {
12-
"nativescript-numeric-keyboard": "file:../src",
13-
"nativescript-unit-test-runner": "~0.3.0",
14-
"tns-core-modules": "~5.2.0"
12+
"nativescript-numeric-keyboard": "../src",
13+
"nativescript-unit-test-runner": "0.7.0",
14+
"tns-core-modules": "~6.0.1"
1515
},
1616
"devDependencies": {
17-
"babel-traverse": "^6.24.1",
18-
"babel-types": "^6.24.1",
19-
"babylon": "^6.16.1",
17+
"babel-traverse": "6.26.0",
18+
"babel-types": "6.26.0",
19+
"babylon": "6.18.0",
2020
"lazy": "1.0.11",
21-
"nativescript-dev-typescript": "~0.6.0",
22-
"tns-platform-declarations": "~5.2.0",
23-
"typescript": "~2.8.0"
21+
"nativescript-dev-webpack": "~1.0.0",
22+
"tns-platform-declarations": "6.0.1",
23+
"tslint": "~5.4.3",
24+
"typescript": "~3.4.0",
25+
"karma-webpack": "3.0.5"
2426
}
2527
}

demo/tsconfig.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
"experimentalDecorators": true,
66
"emitDecoratorMetadata": true,
77
"noEmitHelpers": true,
8-
"noEmitOnError": false,
8+
"noEmitOnError": true,
99
"lib": [
10-
"es2015.iterable",
1110
"es6",
1211
"dom"
1312
],
1413
"baseUrl": ".",
1514
"paths": {
15+
"~/*": [
16+
"app/*"
17+
],
1618
"*": [
17-
"./node_modules/tns-core-modules/*",
1819
"./node_modules/*"
1920
]
2021
}
2122
},
2223
"exclude": [
2324
"node_modules",
24-
"platforms",
25-
"**/*.aot.ts"
25+
"platforms"
2626
]
2727
}

demo/tsconfig.tns.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig",
3+
"compilerOptions": {
4+
"module": "es2015",
5+
"moduleResolution": "node"
6+
}
7+
}

src/angular/nativescript-numeric-keyboard-directives.js

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/numeric-keyboard.ios.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { Color } from "tns-core-modules/color";
2+
import { TextField } from "tns-core-modules/ui/text-field";
23
import {
34
localeProperty,
45
noDecimalsProperty,
56
noIpadInputBarProperty,
67
noReturnKeyProperty,
78
NumericKeyboardApi,
89
NumericKeyboardOptions,
9-
NumericKeyboardViewBase, returnKeyButtonBackgroundColorProperty,
10+
NumericKeyboardViewBase,
11+
returnKeyButtonBackgroundColorProperty,
1012
returnKeyTitleProperty,
1113
TextAndDecimalSeparatorHolder
1214
} from "./numeric-keyboard.common";
@@ -265,6 +267,10 @@ class MMNumberKeyboardDelegateImpl extends NSObject implements MMNumberKeyboardD
265267
}
266268

267269
public numberKeyboardShouldReturn(keyboard: MMNumberKeyboard): boolean {
270+
const owner = <any>this._owner.get();
271+
if (owner) {
272+
owner.notify({ eventName: TextField.returnPressEvent, object: owner });
273+
}
268274
if (this._onReturnKeyPressedCallback) {
269275
return this._onReturnKeyPressedCallback();
270276
} else {

0 commit comments

Comments
 (0)