@@ -180,7 +180,7 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
180180 /// Hide automatically the last separator.
181181 open var autoHideLastRowSeparator = false {
182182 didSet {
183- updateRowSeparatorVisibility ( lastRow )
183+ updateRowsSeparatorVisibility ( )
184184 }
185185 }
186186
@@ -803,9 +803,7 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
803803 guard let row = row else {
804804 return nil
805805 }
806-
807- let previousRow = rowBeforeRow ( row)
808-
806+
809807 // Animate visibility
810808 let removedController = row. controller
811809 animateCellVisibility ( row, animated: animated, hide: true , completion: { [ weak self] in
@@ -817,7 +815,7 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
817815
818816 // When removing a cell the cell above is the only cell whose separator visibility
819817 // will be affected, so we need to update its visibility.
820- self . updateRowSeparatorVisibility ( previousRow )
818+ self . updateRowsSeparatorVisibility ( )
821819
822820 // Remove from the status
823821 self . prevVisibilityState. removeValue ( forKey: row)
@@ -883,31 +881,17 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
883881 }
884882
885883 private func postInsertRow( _ row: ScrollStackRow , animated: Bool , completion: ( ( ) -> Void ) ? = nil ) {
886- // Setup separator visibility for the new cell
887- updateRowSeparatorVisibility ( row)
888-
889- // A cell can affect the visibility of the cell before it, e.g. if
890- // `automaticallyHidesLastSeparator` is true and a new cell is added as the last cell, so update
891- // the previous cell's separator visibility as well.
892- updateRowSeparatorVisibility ( rowBeforeRow ( row) )
893-
894- // Animate visibility
895- animateCellVisibility ( row, animated: animated, hide: false , completion: completion)
884+ updateRowsSeparatorVisibility ( ) // update visibility of the separators
885+ animateCellVisibility ( row, animated: animated, hide: false , completion: completion) // Animate visibility of the cell
896886 }
897887
898888 /// Update the separator visibility.
899889 ///
900890 /// - Parameter row: row target.
901- private func updateRowSeparatorVisibility( _ row: ScrollStackRow ? ) {
902- guard let row = row, row === stackView. arrangedSubviews. last else {
903- return
904- }
905-
906- row. isSeparatorHidden = hideSeparators
907-
908- let isLast = ( row === rows. last)
909- if isLast && autoHideLastRowSeparator {
910- row. isSeparatorHidden = true
891+ private func updateRowsSeparatorVisibility( ) {
892+ let rows = stackView. arrangedSubviews as? [ ScrollStackRow ] ?? [ ]
893+ for (idx, row) in rows. enumerated ( ) {
894+ row. separatorView. isHidden = ( idx == rows. last? . index ? true : row. isSeparatorHidden)
911895 }
912896 }
913897
0 commit comments