Merge branch 'bugfix/carousel_indexing' into 'develop'
indexing safety ### Summary Prevent crash when no molecules are present for the carousel. See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui/-/merge_requests/1041
This commit is contained in:
commit
5bbb4122ec
@ -87,7 +87,7 @@ open class Carousel: View {
|
||||
showPeaking(false)
|
||||
|
||||
// Go to current cell. layoutIfNeeded is needed otherwise cellForItem returns nil for peaking logic. The dispatch is a sad way to ensure the collection view is ready to be scrolled.
|
||||
guard let model = model as? CarouselModel,
|
||||
guard let model = model as? CarouselModel, !model.molecules.isEmpty,
|
||||
(model.paging == true || loop == true) else { return }
|
||||
DispatchQueue.main.async {
|
||||
self.collectionView.scrollToItem(at: IndexPath(row: self.currentIndex, section: 0), at: self.itemAlignment, animated: false)
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
@objcMembers public class CarouselModel: ParentMoleculeModelProtocol, FormFieldProtocol {
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -57,14 +56,14 @@ import UIKit
|
||||
|
||||
guard selectable else {
|
||||
// Use visible item value, else index
|
||||
if let fieldValue = molecules[index].formFieldValue() {
|
||||
if let fieldValue = molecules[safe: index]?.formFieldValue() {
|
||||
return fieldValue
|
||||
}
|
||||
return index
|
||||
}
|
||||
// Use selected item value, else index
|
||||
guard let selectedIndex = selectedIndex else { return nil }
|
||||
guard let fieldValue = molecules[selectedIndex].formFieldValue() else { return selectedIndex }
|
||||
guard let fieldValue = molecules[safe: selectedIndex]?.formFieldValue() else { return selectedIndex }
|
||||
return fieldValue
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user