Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

I'm having problems with onOff switches...left/right not honored, appearance varies
Started by sieler2 Apr 11 2018 04:28 PM

8 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Contributor

  • 105 posts
  • Corona SDK

Hi,

 

I'm looking at widget.newSwitch, "onoff" type...and seem to be encountering a variety of problems:

 

1.  offDirection is ignored

 

2. default switch display is backwards.  

 

        ...except at startup! 

        At startup, the circle is slid to the right for "initialSwitchState" = true or omitted,

        and slid to the left for initialSwitchState = false.

 

3. Simulator is drastically different than Android, graphically:

 

      On simulator, the switch is a white circle inside an oval.

      When flipped to the right (for "off", which *should* be "on" :),

      a green shows in the oval (other than the circle).

 

      On Android, the switch is either a blue rectangle with  

      "on" in it and on the right, or a dark grey rectangle with

      "off" in it and on the left.  The surrounding *rectangle*

      is light gray.

BTW, **KUDOS** to CoronaLabs for putting "on"/"off" in the default graphic!  Thanks!

 

I did notice that the left/right meaning problem was touched on here:

   https://forums.coronalabs.com/topic/71338-newswitch-strange-behaviour/?hl=onoff

but it seemed to be forgotten as other issues were discussed.

 

Attached is a source for app that creates 9 switches ... all possible variations of 

default value = true / false / omitted, and direction for off = left / right / omitted.

 

At startup, note that the middle 3 switches are slid to the right, as they should be,

because they have the value "true" in the isOn field.

 

But, if you tap those three twice, you'll see that slid-to-the-right is actually "off",

indicating that the initial display doesn't match the initial value (problem statement 2 above).

 

If you experiment, you'll find that all 9 switches have "off" to the left (problem statement 1 above).

 

If you compare simulator to Android, you should see the drastic graphical difference.  

I don't mind minor differences (alignment, font size, etc.,), but this is beyond the pale :)

 

As you tap a switch, a message appears at the bottom, noting the new value for the switch,

so you can see activity (useful for the first tap to those middle three!)

 

thanks,

 

Stan

 

 

Attached Files

  • Attached File  foo.tar   47KB   5 downloads


[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,587 posts
  • Corona SDK

better make that a zip not all users can handle a .tar file.

[TOPIC: post.html]
#3

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Contributor

  • 105 posts
  • Corona SDK

Here's a zip

 

BTW, Mac users: you all have the ability to easily unpack tar files ... double click on it and it will expand,

or from the Terminal:

 

   To see contents:   tar tvf foo.tar     

  

   To expand:   tar xvf foo.tar

 

Mac similarly comes with the 'zip' command (as well as the ability to simply double click to expand):

 

   To see contents:     unzip -l foo.zip

 

   To unpack:   unzip foo.zip

 

Windows has native support for unpacking zip files.

 

Stan

 

 

Attached Files

  • Attached File  foo.zip   28.08KB   1 downloads


[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,587 posts
  • Corona SDK

Hi.  I took a look at your code.

 

1 .I agree, 'offDirection' seems to be ignored.

 

2. I saw you were using 'onPress', when you should probably be using 'onRelease'.

 

3. I appreciate that you generated the example and printed lots of information, but if I were the person receiving this code as part of a bug report, I'd want something a lot smaller.

 

This may just be me, but I had trouble working out what was going on at first.

 

(I reduced your example to the bare essence and pre-defined the important parts of the options as a set of 9 options tables.)

 

4. As noted above, I modified your code and I provided a temporary fix for you (find initials RG near bottom).

Attached Files

  • Attached File  bar.zip   55.16KB   2 downloads


[TOPIC: post.html]
#5

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Contributor

  • 105 posts
  • Corona SDK

@roaminggamer

 

As always, I learn from your code ... thanks!

 

I'm not quite in the Lua mindset yet, so I really appreciate seeing some of your code constructs.

Your example and workaround works well!

 

I was using "onPress" because I'd copied/pasted the code from 

https://docs.coronalabs.com/api/library/widget/newSwitch.html

...and, boy, that sure doesn't work right!  :)

(for one thing, the user could slide their finger off the switch,

which will prevent it from toggling, but the "onPress" was already called!)

 

I'll file two bug reports: one on the documentation, and one for offDirection.

 

Stan



[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,587 posts
  • Corona SDK

Please do not file a bug on the docs.

 

Instead, if you think a change is needed, 

 

1. Go to the specific documentation page for newSwitch

 

2. Scroll to the bottom

 

3. Click 'Report an Issue'

 

 

Also, in this case, I think the docs are pretty clear: https://docs.coronalabs.com/api/library/widget/newSwitch.html#onpress-optional

 

Unless that is you think the example would make more sense with an onRelease call.  I can't argue with that.


Edited by roaminggamer, 13 April 2018 - 10:48 AM.


[TOPIC: post.html]
#7

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Contributor

  • 105 posts
  • Corona SDK

@roaminggamer

 

There's a distinct problem with your solution (switch.rotation  = 180)

 

And it becomes visible when you move from the simulator to an Android:

 

on Android the graphic for the on/off switch has the word "on" and "off" in it,

so when you rotate the switch to fix the left/right bug, the word ON and OFF

appear upside down!

 

On iOS, as on the simulator, the graphic for the switch is a hard-to-read-when-off

white circle in a white oval.  (When switched to on, it becomes a white circle

in a green oval.)

 

Stan



[TOPIC: post.html]
#8

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,587 posts
  • Corona SDK

Is that embedded label (i.e. in the texture) or added later as a text object?.   

 

If the latter, you can reach in rotate the label.  Total hack I know.

 

Honestly, the best solution is to fix this yourself and use a local copy of the widget library:

https://github.com/coronalabs/framework-widget

 

 

PS - If you can't tell, I'm not a widget user so I don't remember all these details.


Edited by roaminggamer, 13 April 2018 - 11:27 AM.


[TOPIC: post.html]
#9

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Contributor

  • 105 posts
  • Corona SDK

@rg ... the problem is in the examples, which use onPress instead of onRelease.

 

I hadn't realized CL used a different technique for bug reporting vs. man page problem reporting, thanks.




[topic_controls]
[/topic_controls]