Skip to content

Commit

Permalink
Using returnPress event on html attribute (Angular) #31
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Jul 26, 2019
1 parent 98b0bab commit c821d41
Show file tree
Hide file tree
Showing 41 changed files with 211 additions and 539 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.vscode
*.js
*.log
*.map
*.tgz
!src/angular/*.js
!demo/karma.conf.js
Expand Down
2 changes: 1 addition & 1 deletion demo/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import * as application from 'application';
application.start({ moduleName: "main-page" });
application.run({ moduleName: "main-page" });
8 changes: 8 additions & 0 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ export function pageLoaded(args: EventData) {
}
}

export function textChange(args: EventData) {
console.log("textChange");
}

export function returnPress(args: EventData) {
console.log("returnPress");
}

export function onMyTextLoaded(args: EventData) {
args.object.on("textChange", (args: EventData) => {
let numkey = <TextField>args.object;
Expand Down
2 changes: 1 addition & 1 deletion demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<TextField id="defaultPluginKeyboard" maxLength="4" keyboardType="number" row="2" col="1" text="{{ myTextPlugin }}" loaded="onMyTextLoadedPluginCode"/>

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

<Label row="4" col="0" text="No decimals"/>
<NumKey:NumericKeyboardView row="4" col="1" returnKeyButtonBackgroundColor="#333333" noDecimals="true" text="345"/>
Expand Down
9 changes: 9 additions & 0 deletions demo/app/vendor-platform.android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require("application");
if (!global["__snapshot"]) {
// In case snapshot generation is enabled these modules will get into the bundle
// but will not be required/evaluated.
// The snapshot webpack plugin will add them to the tns-java-classes.js bundle file.
// This way, they will be evaluated on app start as early as possible.
require("ui/frame");
require("ui/frame/activity");
}
3 changes: 3 additions & 0 deletions demo/app/vendor-platform.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// There is a bug in angular: https://github.com/angular/angular-cli/pull/8589/files
// Legendary stuff, its webpack plugin pretty much doesn't work with empty TypeScript files in v1.8.3
void 0;
10 changes: 10 additions & 0 deletions demo/app/vendor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Snapshot the ~/app.css and the theme
const application = require("application");
require("ui/styling/style-scope");
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/);
global.registerWebpackModules(appCssContext);
application.loadAppCss();

require("./vendor-platform");

require("bundle-entry-points");
108 changes: 108 additions & 0 deletions demo/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
module.exports = function (config) {
const options = {

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: ['app/tests/**/*.*'],


// list of files to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [],

customLaunchers: {
android: {
base: 'NS',
platform: 'android'
},
ios: {
base: 'NS',
platform: 'ios'
},
ios_simulator: {
base: 'NS',
platform: 'ios',
arguments: ['--emulator']
}
},

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
};

setWebpackPreprocessor(config, options);
setWebpack(config, options);

config.set(options);
}

function setWebpackPreprocessor(config, options) {
if (config && config.bundle) {
if (!options.preprocessors) {
options.preprocessors = {};
}

options.files.forEach(file => {
if (!options.preprocessors[file]) {
options.preprocessors[file] = [];
}
options.preprocessors[file].push('webpack');
});
}
}

function setWebpack(config, options) {
if (config && config.bundle) {
const env = {};
env[config.platform] = true;
env.sourceMap = config.debugBrk;
options.webpack = require('./webpack.config')(env);
delete options.webpack.entry;
delete options.webpack.output.libraryTarget;
const invalidPluginsForUnitTesting = ["GenerateBundleStarterPlugin", "GenerateNativeScriptEntryPointsPlugin"];
options.webpack.plugins = options.webpack.plugins.filter(p => !invalidPluginsForUnitTesting.includes(p.constructor.name));
}
}
3 changes: 3 additions & 0 deletions demo/nsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"useLegacyWorkflow": false
}
28 changes: 15 additions & 13 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
{
"nativescript": {
"id": "org.nativescript.demo",
"tns-ios": {
"version": "5.2.0"
},
"tns-android": {
"version": "5.2.0"
"version": "6.0.0"
},
"tns-ios": {
"version": "6.0.1"
}
},
"dependencies": {
"nativescript-numeric-keyboard": "file:../src",
"nativescript-unit-test-runner": "~0.3.0",
"tns-core-modules": "~5.2.0"
"nativescript-numeric-keyboard": "../src",
"nativescript-unit-test-runner": "0.7.0",
"tns-core-modules": "~6.0.1"
},
"devDependencies": {
"babel-traverse": "^6.24.1",
"babel-types": "^6.24.1",
"babylon": "^6.16.1",
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"lazy": "1.0.11",
"nativescript-dev-typescript": "~0.6.0",
"tns-platform-declarations": "~5.2.0",
"typescript": "~2.8.0"
"nativescript-dev-webpack": "~1.0.0",
"tns-platform-declarations": "6.0.1",
"tslint": "~5.4.3",
"typescript": "~3.4.0",
"karma-webpack": "3.0.5"
}
}
10 changes: 5 additions & 5 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": false,
"noEmitOnError": true,
"lib": [
"es2015.iterable",
"es6",
"dom"
],
"baseUrl": ".",
"paths": {
"~/*": [
"app/*"
],
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
]
}
},
"exclude": [
"node_modules",
"platforms",
"**/*.aot.ts"
"platforms"
]
}
7 changes: 7 additions & 0 deletions demo/tsconfig.tns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node"
}
}
8 changes: 5 additions & 3 deletions src/angular/nativescript-numeric-keyboard-directives.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/numeric-keyboard.ios.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Color } from "tns-core-modules/color";
import { TextField } from "tns-core-modules/ui/text-field";
import {
localeProperty,
noDecimalsProperty,
noIpadInputBarProperty,
noReturnKeyProperty,
NumericKeyboardApi,
NumericKeyboardOptions,
NumericKeyboardViewBase, returnKeyButtonBackgroundColorProperty,
NumericKeyboardViewBase,
returnKeyButtonBackgroundColorProperty,
returnKeyTitleProperty,
TextAndDecimalSeparatorHolder
} from "./numeric-keyboard.common";
Expand Down Expand Up @@ -265,6 +267,10 @@ class MMNumberKeyboardDelegateImpl extends NSObject implements MMNumberKeyboardD
}

public numberKeyboardShouldReturn(keyboard: MMNumberKeyboard): boolean {
const owner = <any>this._owner.get();
if (owner) {
owner.notify({ eventName: TextField.returnPressEvent, object: owner });
}
if (this._onReturnKeyPressedCallback) {
return this._onReturnKeyPressedCallback();
} else {
Expand Down
Loading

0 comments on commit c821d41

Please sign in to comment.