Skip to content

Commit 42676b6

Browse files
iOS crashes when the return button is pressed when 'decorate' is used #34
1 parent fad7fa4 commit 42676b6

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

demo/app/main-page.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<TextField class="unenhancedTextField" keyboardType="phone" row="1" col="1" text="12.34"/>
1212

1313
<Label row="2" col="0" text="Plugin keyboard (by code, max 4)"/>
14-
<TextField id="defaultPluginKeyboard" maxLength="4" keyboardType="number" row="2" col="1" text="{{ myTextPlugin }}" loaded="onMyTextLoadedPluginCode"/>
14+
<TextField id="defaultPluginKeyboard" maxLength="4" keyboardType="number" row="2" col="1" text="{{ myTextPlugin }}" loaded="onMyTextLoadedPluginCode" returnPress="returnPress"/>
1515

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

demo/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
"nativescript": {
33
"id": "org.nativescript.demo",
44
"tns-android": {
5-
"version": "6.0.0"
5+
"version": "6.0.2"
66
},
77
"tns-ios": {
8-
"version": "6.0.1"
8+
"version": "6.0.2"
99
}
1010
},
1111
"dependencies": {
1212
"nativescript-numeric-keyboard": "../src",
1313
"nativescript-unit-test-runner": "0.7.0",
14-
"tns-core-modules": "~6.0.1"
14+
"tns-core-modules": "~6.0.7"
1515
},
1616
"devDependencies": {
1717
"babel-traverse": "6.26.0",
1818
"babel-types": "6.26.0",
1919
"babylon": "6.18.0",
2020
"lazy": "1.0.11",
2121
"nativescript-dev-webpack": "~1.0.0",
22-
"tns-platform-declarations": "6.0.1",
22+
"tns-platform-declarations": "~6.0.7",
2323
"tslint": "~5.4.3",
2424
"typescript": "~3.4.0",
2525
"karma-webpack": "3.0.5"

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* iOS and Android apis should match.
33
* It doesn't matter if you export `.ios` or `.android`, either one but only one.
44
*/
5-
export * from './numeric-keyboard.ios';
5+
export * from './numeric-keyboard.android';
66

77
// Export any shared classes, constants, etc.
88
export * from './numeric-keyboard.common';

src/numeric-keyboard.ios.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class NumericKeyboard implements NumericKeyboardApi, TextAndDecimalSepara
6868
// not exposing this just yet (not too useful)
6969
// keyboard.returnKeyButtonStyle = MMNumberKeyboardButtonStyleDone; // (Done = default, there's also White and Gray)
7070

71-
this._keyboardDelegate = MMNumberKeyboardDelegateImpl.initWithOwner(new WeakRef(this));
71+
this._keyboardDelegate = MMNumberKeyboardDelegateImpl.initWithOwner(new WeakRef(this), args.textField);
7272
this._keyboard.delegate = this._keyboardDelegate;
7373

7474
if (args.onReturnKeyPressed) {
@@ -209,10 +209,12 @@ class MMNumberKeyboardDelegateImpl extends NSObject implements MMNumberKeyboardD
209209
public static ObjCProtocols = [MMNumberKeyboardDelegate];
210210

211211
private _owner: WeakRef<TextAndDecimalSeparatorHolder>;
212+
private _textFieldToNotify?: TextField;
212213

213-
public static initWithOwner(owner: WeakRef<TextAndDecimalSeparatorHolder>): MMNumberKeyboardDelegateImpl {
214+
public static initWithOwner(owner: WeakRef<TextAndDecimalSeparatorHolder>, textFieldToNotify?: TextField): MMNumberKeyboardDelegateImpl {
214215
const delegate = <MMNumberKeyboardDelegateImpl>MMNumberKeyboardDelegateImpl.new();
215216
delegate._owner = owner;
217+
delegate._textFieldToNotify = textFieldToNotify;
216218
return delegate;
217219
}
218220

@@ -267,10 +269,15 @@ class MMNumberKeyboardDelegateImpl extends NSObject implements MMNumberKeyboardD
267269
}
268270

269271
public numberKeyboardShouldReturn(keyboard: MMNumberKeyboard): boolean {
270-
const owner = <any>this._owner.get();
271-
if (owner) {
272-
owner.notify({ eventName: TextField.returnPressEvent, object: owner });
272+
if (this._textFieldToNotify && this._textFieldToNotify.notify) {
273+
this._textFieldToNotify.notify({ eventName: TextField.returnPressEvent, object: this._textFieldToNotify });
274+
} else {
275+
const owner = <any>this._owner.get();
276+
if (owner && owner.notify) {
277+
owner.notify({ eventName: TextField.returnPressEvent, object: owner });
278+
}
273279
}
280+
274281
if (this._onReturnKeyPressedCallback) {
275282
return this._onReturnKeyPressedCallback();
276283
} else {

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-numeric-keyboard",
3-
"version": "4.3.0",
3+
"version": "4.3.1",
44
"description": "Handy and elegant numeric keyboard for iOS NativeScript apps. On Android we fall back to the regular numeric keyboard.",
55
"main": "numeric-keyboard",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)