Skip to content

[NS8] isEnabled property on Button is not propagating to native's enable property (Appium, iOS, Android) #9455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vigdora opened this issue Jun 23, 2021 · 8 comments
Labels

Comments

@vigdora
Copy link

vigdora commented Jun 23, 2021

back in the days of Native Script 7, on using isEnabled property with Button I could see
on my Appium desktop that enabled property is changing accordingly, i.e.
when isEnabled=true, so enabled got true as well...

image

but now with NS8, enabled property is true no matter what I pass to isEnabled on the Button element.
the weird part is that the button functionality plays correctly, it is just that Appium keeps the attribute true...

I have switched from NS7 to NS8 multiple times to validate that I see correctly - and I strongly believe it is a bug on NS8.
also, our automation started failing when expecting this property to be false (and it passed with NS7)

  1. can someone with Appium and NS8 test it as well?
  2. can it be an issue with Appium or would it be an NS8 bug?
@rigor789
Copy link
Member

This is related to the a11y changes, setEnabled is correctly called on the View, however the accessibilityState is not changed, and appium ends up reading the wrong state.

A simple workaround would be to add the following css:

*:disabled { 
  a11y-state: disabled; 
}

However a proper fix would be required in core.

@m-abs I was thinking of setting it here inside the valueChanged callback:

export const isEnabledProperty = new Property<ViewCommon, boolean>({
name: 'isEnabled',
defaultValue: true,
valueConverter: booleanConverter,
valueChanged(this: void, target, oldValue, newValue): void {
target._goToVisualState(newValue ? 'normal' : 'disabled');
},
});
isEnabledProperty.register(ViewCommon);
however I'm not sure if there would be any implications of that change.

@rigor789 rigor789 added the bug label Jun 24, 2021
@m-abs
Copy link
Contributor

m-abs commented Jun 28, 2021

however I'm not sure if there would be any implications of that change.

It might cause some inconsistency problems, if a11y-state: disabled and isEnabled = false are used at the same time. But if you handle that corner-case, I agree.

@vigdora
Copy link
Author

vigdora commented Jun 29, 2021

do you think it can be fixed for next patch?

@vigdora
Copy link
Author

vigdora commented Jul 5, 2021

@rigor789
I think your workaround is not complete:
it worked only for the case where the button isEnabled was set to false to begin with (Appium showed enabled=false as expected)
but now I have noticed that when we dynamically change the button isEnabled from false to true
Appium still shows enabled=false...

btw,
when changing from true to false dynamically (the other way around) it seems to work...
so as I mentioned- the issue is on changing from false to true dynamically, where it stays false

can you try and help us to come out with better solution?

@vigdora vigdora changed the title [NS8] isEnabled property on Button is not propagating to native's enable property (Appium, iOS, android) [NS8] isEnabled property on Button is not propagating to native's enable property (Appium, iOS, Android) Jul 5, 2021
@rigor789
Copy link
Member

The following workaround (the css one can be removed, this one replaces it) will fix the issue until we implement a fix in core:

import {  Observable,  AccessibilityState } from '@nativescript/core'

Observable.on('isEnabledChange', (args) => {
  args.object.accessibilityState = args.value ? undefined : AccessibilityState.Disabled;
})

This can be placed in the application entry file (main.js/ts, app.js etc).

@IlIAntonIlI
Copy link

IlIAntonIlI commented Sep 5, 2023

Nativescript 8.5.0 , Angular 15.2.0

Added

import {  Observable,  AccessibilityState } from '@nativescript/core'

Observable.on('isEnabledChange', (args) => {
  args.object.accessibilityState = args.value ? undefined : AccessibilityState.Disabled;
})

to my main.ts file, but it didn't help. So, I decided to add some console logs to review the behavior. It turned out that callback was not called on enabledProperty change.

To debug place where event is triggered, I added console logs in
/node_modules/@nativescript/core/ui/core/properties/index.js as well

// beginning of my logs
if (eventName === 'isEnabledChange') {
    console.log('event name: ', eventName)
    console.log('object: ', this)
    console.log('has listeners:', this.hasListeners(eventName))
}       
// end of my logs

if (this.hasListeners(eventName)) {
    this.notify({
        object: this,
        eventName,
        propertyName,
        value,
        oldValue,
    });
}

And got:
logs

Since the listener for isEnabledChange is not set for every view by default, this.hasListeners(eventName) returns false for each view -> the isEnabledChange event is not triggered -> the global handler has nothing to process -> the enabled property is not changed in appium.

Is there any way to overcome this problem?

@CatchABus
Copy link
Contributor

@IlIAntonIlI I think we'll need to reconsider few things for accessibilityState property.
I tend to resort to updating enabled and trait -> UIAccessibilityTraitNotEnabled at the same time which is the most recommended approach.

@insytes
Copy link
Contributor

insytes commented May 24, 2024

+1 still seeing this problem in Appium

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants