android
android copied to clipboard
Button [isEnabled] Android crash.
Version tns-android: 6.2.0
Button [isEnabled] is crashing in android.
<Button text="Login" (tap)="login()" [isEnabled]="isEnabled()" class="my-button"></Button>
System.err: Caused by: java.lang.Exception: Failed resolving method setEnabled on class android.widget.TextView
Hi! Could you send a sample application which has this issue? Also, did you try changing only the android runtime version to 6.1.0 in order to see if the problem is indeed in the runtime?
I had the same android crash problem with :
// TS: list = [];
// Template : <Button [isEnabled]="list.length" text="label"></Button>
And I fixed it by using !!list.length
or list.length > 0
which is a bit weird .. list.length
should totally work
Same issue:
<Button v-if="questionType === 'textarea'" backgroundColor="#67a7c4" color="#FFFFFF" height="48" width="auto" padding="0 28" fontSize="16" class="tcmg-button mb-3" text="Check it out" :isEnabled="canSubmitTextArea" @tap="handleAnswerSelected()" ></Button>
Works like a charm in iOS but crashed in Android.
Anyone knows how to fix this?
Also me I had the same issue but I solved it assign an initial value to the boolean ( don't ask me why ). So to be clear : public myBool: boolean; --> go in crash ( java.lang.Exception: Failed resolving method setEnabled on class android.widget.TextView ) public myBool = false; --> it works !
It's not about the initial value actually. isEnabled
should receive strictly boolean
. So instead of using [isEnabled]="someData"
please use at least [isEnabled]="!!someData"
and it will work correctly
The !! should be done internally in the directive.
Like in js/ts if (array.length)
is correct and doesn't need an explicit boolean if (array.length > 0)
I agree. This just how I see it works now
/**
* Fix bug in {N} button implementation by explicitly
* casting value as boolean
*/
(function fixButton(): void {
if (isIOS) return;
function fixedIsEnabled(value: any) {
//console.log('fixedIsEnabled', value, Boolean(value));
this.nativeView?.setEnabled(!!value);
}
Button.prototype[isEnabledProperty.setNative] = fixedIsEnabled;
})();