xmartlabs / Eureka

Elegant iOS form builder in Swift
https://eurekacommunity.github.io
MIT License
11.78k stars 1.33k forks source link

SegmentedRow crash due to selectedSegmentIndex == -1 #2238

Open mikeymike9000 opened 1 year ago

mikeymike9000 commented 1 year ago

When selecting different Section Segments sometimes my app crashes due to segmentedControl.selectedSegmentIndex (within class SegmentedCell) returning a "-1" instead of legitimate value that is >=0

Existing Eureka code: @objc (segmentedValueDidChange) func valueChanged() { row.value = (row as! OptionsRow).options?[segmentedControl.selectedSegmentIndex] }

Hack I'm using to avoid the crash: @objc (segmentedValueDidChange) func valueChanged() { if segmentedControl.selectedSegmentIndex == -1 { segmentedControl.selectedSegmentIndex = 0 } row.value = (row as! OptionsRow).options?[segmentedControl.selectedSegmentIndex] }

mats-claassen commented 1 year ago

Have you been able to reproduce this issue? How does it happen that the selectedSegmentedIndex is -1? Does that happen when no segment is selected?

mikeymike9000 commented 1 year ago

Sorry I don't have more details yet and haven't figured out how to reproduce. It happens quite often so I'll create a video and screenshots next time I run into it. It occurs seemingly randomly when changing from one segment to another after setting them up like this:

<<< SegmentedRow("segs") { $0.value = "Tab1"; $0.options = ["Tab1", "Tab2", "Tab3"] } <<< SegmentedRow ("segsTab1") { $0.value ="SubTab1"; $0.options = ["SubTab1", "SubTab2", "SubTab3"]; $0.hidden = "$segs != 'Tab1'" }

It occurs on devices as well as simulators and "My Mac (Designed for iPad)", and has been occurring through MacOS 12/13 and Xcode 13/14.

mikeymike9000 commented 1 year ago

ok I figured out how to recreate:

1) run my iOS app as "My Mac (Designed for iPad)" 2) click on the window of another open app to make that app active 3) click back in the window of my app directly on a Eureka segment

I can only recreate this when running as "My Mac (Designed for iPad)" app and only when the app Touch Alternatives is turned off.

Screenshot 2022-12-13 at 3 42 03 PM
mikeymike9000 commented 1 year ago

https://user-images.githubusercontent.com/47927115/207429707-5fb1e605-65ac-4324-9eef-257a2f49bb3f.mov

mikeymike9000 commented 1 year ago

I believed this had also occurred in simulators and on devices for the past year or more but I could be mistaken.

mikeymike9000 commented 1 year ago

here's an example where it shows the issue including the hack where I select index 0 when avoiding the crash..

https://user-images.githubusercontent.com/47927115/207432070-301bac31-407e-4570-880c-b9fb28ff4776.mov

mikeymike9000 commented 1 year ago

NOTE: the issue also occurs when my app is created as Ad Hoc or installed via TestFlight.

mats-claassen commented 1 year ago

Instead of setting to 0, did you try just returning without doing anything?

mikeymike9000 commented 1 year ago

Returning without doing anything deselects the Segment's tab visually but doesn't actually hide the tab's content (see attached video). I will continue manually setting the index to 0 in case having it 'unset' while its content is accessible could cause other issues. My current hack/workaround is fine for me, I just wanted to let you know.

I'm also using Swift Package Manager, so what I've done is make a local copy of SegmentedRow.swift in my Xcode project, and renamed the file and class to be SegmentedRowCustom.

https://user-images.githubusercontent.com/47927115/207638150-07a52ce9-9fa5-48e9-97eb-dd3da6f8f460.mov