[TIMOB-2908] iOS: Switch - Disable animation on init and allow developer to disable for setValue
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Trivial |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-11-23T22:15:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.2.0, Release 5.1.2 |
Components | iOS |
Labels | api, switch |
Reporter | Alan Leard |
Assignee | Chee Kiat Ng |
Created | 2011-04-15T03:32:37.000+0000 |
Updated | 2015-11-26T03:47:56.000+0000 |
Description
When loading a switch with a value set to 'true' the switch shows an animation going from 'off' to 'on'.
Users would like a property added to the switch object of 'animate' as a boolean value, to turn off the animation on-load if the value of the switch is preset to true.
Reference ticket: http://developer.appcelerator.com/helpdesk/view/67301
Any movement on this? Seems like an oversight that it is still not resolved? Stock iOS apps do not exhibit this behaviour .
[~ingo], I say we even just set the initial animation off by default. It will then still animate when the users taps it but not when you set it programmatically. I've recorde 2 movies to show the difference. The next dropbox folder also includes a module that disabled the animation. * https://www.dropbox.com/sh/aq88p58jc3sfe63/AABUm5MHzobnqH16fiabYRrVa Otherwise I'd would indeed request for
setValue(value, animated)
.PR: https://github.com/appcelerator/titanium_mobile/pull/6539
Does this stop the creation animation [~fokke] or are you providing a toggle for the animation state? Ideally the animation should not exist on creation value of true. However toggling the state later in code could allow animation without issue. An option to toggle post creation animation is nice but not required. Just seeking clarification on the result of the PR.
it will disable the animation when you programmatically set the value. When the user toggles it will still animate.
I am not sure this is the correct direction. With ScrollableView you have the choice to animate from the current state to the chosen state or to simply arrive at the new state without animation. This logic occurs in many of the views with animation. The use of animation (which is ever increasing) is to show the user a change of state. During creation animation is rarely if ever required as the presented information 'simply is'. However if the developer makes a code change on behalf of the user (not setting a default value) then the idea IS to draw attention to the thing that changed. So I still believe that creation value should NOT animate, post creation SHOULD animate, although there is good logic to have that as an OPTION.
At creation, the switch should be rendered on screen already set to its starting value. This is not the case currently. If you create a switch with a starting value of true/on, you first see the switch in the false/off position, then a moment later it changes to true/on. Whether it animates that way or not is beside the point. A switch with a starting value of true/on should never be shown as false/off. For subsequent changes (after the initial rendering), yes, I'd like to have the flexibility to enable/disable animation when programmatically setting the value.
+1
How on earth is this still an outstanding item? Created April 2011, Bumped multiple times; including by myself almost 18 months ago. PR ready at the start of the year but still has a priority of "Trivial" and no schedule info. Why are core elements like this being so long forsaken.
FYI. We should take the PR into 5.1.1
Sample code:
Steps to test
1. Set 'Slow Animations' on ios simulator (cmd-T) 2. build and run sample code 3. click 'toggle switch' 4. click 'set animated' 5. click 'toggle switch' 6. Repeat step 2 to 3, but changing sample codeanimated: true
7. Repeat step 2 to 3, but changing sample code to remove animated: ENTIRELYExpected results
2. Switch value is 'true' with ZERO animation 3. Switch value will change with ZERO animation 5. Switch value will change WITH animation 6. This is the test case with animated property set to false during creation. there is still ZERO animation when launched, but clicking 'toggle switch' you can see values change WITH animation. 7. This is the test case whereby you don't set the animated property at all (default is TRUE). there is still ZERO animation when launched, but clicking 'toggle switch' you can see values change WITH animation.Master PR: https://github.com/appcelerator/titanium_mobile/pull/7456 5_1_X backport PR: https://github.com/appcelerator/titanium_mobile/pull/7457 (Do not merge until 5.1.0.GA)
[~cng] and [~hansknoechel] (reviewing) I don't think the implementation is clear. Having a global
animation
property on the object doesn't make clear what exactly is (not) animated. You'd easily think that if the user toggles it the control it will not animate either, which is not correct (right?) - it will always animate when the user toggles it. It would find this a lot clearer and also more in line with other API's like: https://appcelerator.github.io/appc-docs/latest/#!/api/showParams-property-animatedAfter attempting to achieve the 2nd proposition, i realised it's not quite possible to code. We cannot do switch.setValue(Boolean, Dictionary). If you observe OptionDIalog.show carefully, we are actually intending to do:
And this would be a problem for UISwitch creation. because you are expecting people to do this now:
The reason why is because Titanium uses the same setValue method during creation. It is possible to do it such that value can either be a Boolean or Dictionary so that we can stick back to the old style for creation while maintaining the new style for post-setValue, but in the future, deprecating setValue(Boolean) will then be an issue. That would imply that we need people to createSwitch in the new style. Unless, we introduce a new method called setValueWithAnimation(Dictionary). and consider setValue(Boolean) inherently uses default animation = true. Or. Use my proposition for a global animated property.
Even if Titanium uses setValue on creation, how is it a problem if the second argument is optional?
I did not understand how the points 2-7 on expected results helps explain the situation. This needs to be really simple;
Switch animations _should not_ occur if property 'value' is set to 'true' on creation
Switch animations _should_ occur during any user interaction.
It would be ideal if *setValue* gained an optional parameter of animated (where the default is true)*switch.setValue(true)* = animation if previous value was false
*switch.setValue(false)* = animation if previous value was true
*switch.setValue(true, true)* = animation if previous value was false
*switch.setValue(false, true)* = animation if previous value was true
*switch.setValue(true, false)* = no animation
*switch.setValue(false, false)* = no animation
Optional syntax;This would then use a similar property syntax as method *open* on *window*.
Maybe i can explain this another way. Value is a property. setValue() and getValue() is a property setter and getter. Not really a method that we can do the fancy stuff like setValue(Boolean, (optional){Dictionary}) or to better understand this, what can i expect to get for getValue() if i somehow implemented the above method? The closest way we can achieve this is to set the property to an array. Which we cannot do because of parity with other platforms. So only my global animated makes sense here. OR, we can make an exclusive ios method setValueWithAnimation(Bool, Dict).
[~core13], sorry if my test steps aren't clear. Rest assured, the most important part is already fixed in this PR: {quote} Switch animations should not occur if property 'value' is set to 'true' on creation Switch animations should occur during any user interaction. {quote} You can test out the PR if you want while we are still reviewing the latter: {quote} It would be ideal if setValue gained an optional parameter of animated (where the default is true) {quote}
[~cng] I found a proxy that does the exact same thing which we can copy from: * https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiUISlider.m#L235-L247 * https://appcelerator.github.io/appc-docs/latest/#!/api/Titanium.UI.Slider-method-setValue
Discussed the issue with [~cng] and [~penrique] last week: It makes more sense to use the solution of Kiat, instead of configuring it using an options object. It is more flexible and internally much cleaner. Please review the approve and I will merge it after we agreed.
Well if there's no other solution I guess we better resolve it with what we can do. Maybe rename
animated
to something likesetValueAnimated
to make it clear it does *not* effect animation when user changes value?So no solution for or wish to attend to the following? {quote} It would be ideal if setValue gained an optional parameter of animated (where the default is true) {quote}
Yes, it seems so :(
It is a architectural decision. You can make a switch non-animated by default:
or leave it animated (default):
or change its animation behavior for manual cases:
This feature will be available in 5.1.1 and 5.2.0.
Verified as fixed, ran the sample code & test cases provided by [~cng] and build with SDK:
5.1.1.v20151123142050
. Toggling animation on switch functions correctly, and removing theanimated
property from the code sets the switch to be animated by default. Tested on: Devices: iPhones 6S (9.1) Simulators: (9.1) Mac OSX El Capitan 10.11 (15A284) Ti SDK: 5.1.1.v20151123142050 Appc Studio: 4.4.0.201511182122 Appc NPM: 4.2.2 Appc CLI: 5.1.0-60 Alloy: 1.7.26 Xcode 7.1(7B91b) Node v0.12.7 *Closing ticket.*To Note: This ticket is marked 5.1.2 but PR was merged in 5.1.1GA