android icon indicating copy to clipboard operation
android copied to clipboard

Button [isEnabled] Android crash.

Open juanpicuervo opened this issue 5 years ago • 8 comments

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

juanpicuervo avatar Nov 07 '19 19:11 juanpicuervo

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?

vmutafov avatar Nov 08 '19 11:11 vmutafov

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

jscti avatar Jan 17 '20 14:01 jscti

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?

jonathan-giardino avatar Apr 23 '20 08:04 jonathan-giardino

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 !

ganoraa avatar Oct 23 '20 08:10 ganoraa

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

SergeyMell avatar Nov 15 '20 16:11 SergeyMell

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)

jscti avatar Nov 15 '20 18:11 jscti

I agree. This just how I see it works now

SergeyMell avatar Nov 15 '20 19:11 SergeyMell

/**
 * 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;
})();

AdamAtri avatar Apr 05 '22 19:04 AdamAtri