[TIMOB-27977] TiAPI: Add "isTrusted" property to Ti.UI.Slider "change" event
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-08-06T14:33:02.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 9.1.0 |
Components | Android, iOS |
Labels | android, event, iOS, slider |
Reporter | Michael Gangolf |
Assignee | Joshua Quick |
Created | 2020-05-20T10:50:09.000+0000 |
Updated | 2021-02-17T05:40:13.000+0000 |
Description
Component: Ti.UI.Slider
Platform: Android
At the moment it is not possible to differentiate between a "user slide" and a "change of the value by code" inside the change event. There is already a
fromUser
parameter inside the listener:
https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java#L315
Exposing that value inside the event:
https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISlider.java#L361
and changing the calls to that function to "onProgressChanged(seekBar, curPos, false);" (last parameter false) would only output true if the slider was dragged by the user.
PR and Test case will follow
PR (master): https://github.com/appcelerator/titanium_mobile/pull/11717
[~michael], perhaps a better solution would be that a "change" event should *+NOT+* be fired when setting the
Slider
"value" property programmatically? This is howTextField
andTextArea
works. Although doing it this way may qualify it as a breaking-change. _(Your approach is not a breaking-change.)_ I just checkedPicker
and it fire a "change" event when changing its selection programmatically too.Perhaps the non breaking change for now and then make it behave the same way like TextFields in a later SDK?
After putting some more thought into this, I agree with you. I don't think we should make a breaking-change to this. It's not "wrong" of it to fire a change event when the value is changed programmatically. In fact, many UI frameworks work this way. When developing for the web, events have an
isTrusted
boolean property which is settrue
if it was generated by end-user interaction. Perhaps we should do the same? It's not the best property name, but it is a standard name that web developers are familiar with. What do you think? https://developer.mozilla.org/docs/Web/API/Event/isTrustedGuys I don't get it...I was finding solution on Ti.Slack about this, because Android returns this property natively and it is not exposed to Titanium app. That's it. I think that simple solution(already prepared by Michael) is the best - just expose that fromUser property and done...
[~max87], Titanium is a cross-platform framework. What we implement on Android also needs to be implemented on iOS. And it's also preferred that we implement things the JavaScript way since Titanium appeals to web developers. Titanium's "event" object already replicates several several standard properties such as [type](https://developer.mozilla.org/en-US/docs/Web/API/Event/type) and [bubbles](https://developer.mozilla.org/en-US/docs/Web/API/Event/bubbles). We're talking about implementing this ticket via [isTrusted](https://developer.mozilla.org/docs/Web/API/Event/isTrusted) as well.
updated the PR and changed the parameter to "isTrusted". Added the value to the documentation, too
@Joshua Quick I understand. What I meant was, that solution is already prepared(I think that it's not important if parameter is called fromUser or isTrusted, important is, that such a parameter is exposed to Ti developers). For iOS there is no such a parameter in native side(AFAIK). Strange is, that when I implemented this funcionality as custom, there was a performance issues and it was not working well. As I made changes to SDK and exposed fromUser, everything is okay. On the other side, iOS has no performance issues with custom parameter(original solution for Android).
FR Passed, waiting on Jenkins build.
merged to master for 9.1.0 target
Fix verified on build 9.1.0.v20200804082025. Ticket closed.