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?
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?
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…
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.
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.
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
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 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.
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?