widget.newPickerWheel selected rows issue

Hi, 

I’m creating a picker wheel widget like this one: 

Screenshot%202013-11-13%2011.00.59.png

Where the user can select date/time. 

If I tap one of the values (for example 2014 in the middle column) and then read that via 

pickerWheel:getValues () [3] 

I get a table - with index and value of that selected row (so, { 2, “2014” }). 

But if I “scroll” to 2014 value (dragging the wheel, not tapping on the value), the picker wheel doesn’t “snap” to the 2014 in the center and then the pickerWheel:getValues () returns nil in the 3rd column. 

Is it a bug of some kind, or is there some workaround for that? 

It is a bug with a fix promised long time ago. We are all hoping this fix will be released real soon.

Anything else we can use for easy date-picker until it gets fixed? 

Nothing that I’m aware of. I’m sorry.

Hi @kender,

I’m investigating a similar issue now with the picker wheel, where if the user pulls a value (touches and drags) and then lets up outside the “bars”, it doesn’t always snap back to the nearest value. Does this sound like the same behavior you’re referring to here?

Thanks,

Brent

Hi Brent

In fact I don’t observe any snapping back. And when there’s no snapping, the value for that column returned is nil :( 

Any workaround? 

We’re investigating the possible snap-back issue now. I do get snap-back in most cases using the latest build, but sometimes it doesn’t snap back (in the instance I described in my last post). We’re investigating the cause of this now. So, there’s not a workaround at the moment…

Best regards,

Brent

Is the current code, from the newest build, the same as in the github repository: https://github.com/coronalabs/framework-widgets/blob/master/widgetLibrary/widget_pickerWheel.lua ? If it is, I could probably spend some time on it as well :wink: (I was advocating hard the use of Corona for the app [medical application], instead of other options, and it really kicked my ass now ;) 

Hi @kender,

That repo version is not the most current, but you can explore its methods if you wish. One thing about picker wheel (and it’s rather tricky to find a resolution for) is when the user drags outside of the wheel’s “bounds”, thus not triggering an ended/cancelled phase… so the column doesn’t know if/when to snap back in that case. We’re pondering various solutions for this.

Brent

Well, I’m getting snapping for a moment, then it stops… 

Here’s the video: https://dl.dropboxusercontent.com/u/51630060/pickerWheelNotSnapping.mp4

Gonna debug it with the code from github, if there’s no way to get my hands on the most current version :) 

I’m having the exact same issue and the problem with the picker wheel happens in both the simulator and in builds on my device. If user drags mouse or slides their finger, the wheel doesn’t snap to the nearest value making it pretty much impossible to select a value from the wheel using these methods (the values can’t be read when the wheel doesn’t snap into position). However, if the user clicks or taps on a value, the wheel correctly scrolls to the correct position and the value can be read programatically with no problem at all.

If I could read any value at all from it I could force it to snap to the nearest whole number, but that isn’t possible.

Verified that the issue is still there with the latest daily build (#1260) using the widget demo sample app. If you give the picker a fast spin it comes to stop and snaps to place. If you move the picker and let it go right above the line it doesn’t snap. Its almost as if it can’t decide which way to snap so it goes nowhere… See attached screen capture. Thanks for your attention.

@Brent

So, a question raises - is it realistic to believe that this issue would be fixed soon (like, in a couple of days)? If not, is it possible to release the current, most recent version of widgets code to github, so maybe “outside world” could fix that bug? 

So, I decided that I need to do something with it. The project couldn’t really wait too long :slight_smile:

Since I needed the values read from the picker, but the “snapping” behaviour wasn’t that critical, I implemented a simple fix that returned me the values even if the rows weren’t aligned perfectly. 

I used the github version of Widgets 2.0 (https://github.com/coronalabs/framework-widgets-legacy). 

I needed to modify the view:_getValues () function to handle the nil-value issue, so now it looks like this:

 -- Function to retrieve the column values function view:\_getValues() local values = {} -- Loop through all the columns and retrieve the values for i = 1, #self.\_columns do print ( i, self.\_columns[i].\_values ) values[i] = self.\_columns[i].\_values if values[i] == nil then values[i] = getNearestValueForColumn ( i ) end end return values end

And the getNearestValueForColumn ( i ) function is something I added at the top of the file: 

 local function getNearestValueForColumn ( columnIndex ) local cp = viewColumns[columnIndex]:getContentPosition () local rh = 40 -- row height local y1, y2 = viewColumns[columnIndex].contentHeight / 2 - rh / 2, viewColumns[columnIndex].contentHeight / 2 + rh / 2 local y\_mid = viewColumns[columnIndex].contentHeight / 2 local pos = cp local idx = 1 local idxFound = nil local dist = 100000 for idx = 1, viewColumns[columnIndex]:getNumRows () do local pos = cp + ( idx - 0.25 ) \* rh local d = math.abs ( pos - viewColumns[columnIndex].contentHeight / 2 ) if d \< dist then idxFound = idx dist = d end end idx = idxFound print ( "Row idx: ", idx ) local phase = "release" -- print ( "Did tap", phase) local row = { index = idx, value = opt.columnData[columnIndex].labels[idx] } return row end

Now the picker doesn’t snap nicely, so this isn’t fixed (I tried to achieve that too, but my solution was messing something else up; maybe I’ll get back to this if time allows) but at least the values can be read from the rows. 

Hope this can help anyone :slight_smile:

Just tried WidgetDemo in #2076 and this issue seems to be fixed.! Good work. :slight_smile:

Nope. The snapping is still not consistent. This still needs work.

It is a bug with a fix promised long time ago. We are all hoping this fix will be released real soon.

Anything else we can use for easy date-picker until it gets fixed? 

Nothing that I’m aware of. I’m sorry.

Hi @kender,

I’m investigating a similar issue now with the picker wheel, where if the user pulls a value (touches and drags) and then lets up outside the “bars”, it doesn’t always snap back to the nearest value. Does this sound like the same behavior you’re referring to here?

Thanks,

Brent