Take separatorWidth as part of the `SplitScreenContainerScreen` model
MODIFY
swift/Samples/SplitScreenContainer/DemoApp/DemoWorkflow.swift
swift/Samples/SplitScreenContainer/DemoApp/DemoWorkflow.swift
@@ -78,7 +78,9 @@ extension DemoWorkflow {
return SplitScreenContainerScreen(
leftScreen: leftScreenFor(state: state, context: context),
rightScreen: FooScreen(title: "Right screen", backgroundColor: .green, viewTapped: { sink.send(.viewTapped) }),
- ratio: DemoWorkflow.sizes[state % DemoWorkflow.sizes.count]
+ ratio: DemoWorkflow.sizes[state % DemoWorkflow.sizes.count],
+ separatorColor: .black,
+ separatorWidth: 1.0 * CGFloat(state)
)
}

MODIFY
swift/Samples/SplitScreenContainer/Sources/SplitScreenContainerScreen.swift
swift/Samples/SplitScreenContainer/Sources/SplitScreenContainerScreen.swift
@@ -31,16 +31,21 @@ public struct SplitScreenContainerScreen<LeftScreenType: Screen, RightScreenType
/// The color of the `separatorView` displayed between `leftScreen`'s and `rightScreen`'s views.
public let separatorColor: UIColor
+ /// The width of the `separatorView` displayed between `leftScreen`'s and `rightScreen`'s views.
+ public let separatorWidth: CGFloat
+
public init(
leftScreen: LeftScreenType,
rightScreen: RightScreenType,
ratio: CGFloat = .third,
- separatorColor: UIColor = .black
+ separatorColor: UIColor = .black,
+ separatorWidth: CGFloat = 1.0
) {
self.leftScreen = leftScreen
self.rightScreen = rightScreen
self.ratio = ratio
self.separatorColor = separatorColor
+ self.separatorWidth = separatorWidth
}
}

MODIFY
swift/Samples/SplitScreenContainer/Sources/SplitScreenContainerViewController.swift
swift/Samples/SplitScreenContainer/Sources/SplitScreenContainerViewController.swift
@@ -33,15 +33,25 @@ public final class SplitScreenContainerViewController<LeftScreenType: Screen, Ri
return
}
- UIView.animate(withDuration: 0.25) {
- self.view.setNeedsLayout()
- self.view.layoutIfNeeded()
+ needsAnimatedLayout = true
}
}
+
+ private var currentSeparatorWidth: CGFloat {
+ didSet {
+ guard oldValue != currentSeparatorWidth else {
+ return
+ }
+
+ needsAnimatedLayout = true
+ }
}
+ private var needsAnimatedLayout = false
+
required init(screen: ContainerScreen, viewRegistry: ViewRegistry) {
currentRatio = screen.ratio
+ currentSeparatorWidth = screen.separatorWidth
super.init(screen: screen, viewRegistry: viewRegistry)
}
@@ -59,8 +69,17 @@ public final class SplitScreenContainerViewController<LeftScreenType: Screen, Ri
//Intentional force of layout pass after updating the child view controllers
view.layoutIfNeeded()
- //Update the current ratio in an animated fashion if needed
currentRatio = screen.ratio
+ currentSeparatorWidth = screen.separatorWidth
+
+ if needsAnimatedLayout {
+ needsAnimatedLayout = false
+
+ UIView.animate(withDuration: 0.25) {
+ self.view.setNeedsLayout()
+ self.view.layoutIfNeeded()
+ }
+ }
}
override public func viewDidLoad() {
@@ -82,7 +101,7 @@ public final class SplitScreenContainerViewController<LeftScreenType: Screen, Ri
let (firstSlice, rightRect) = view.bounds.divided(atDistance: distance, from: .minXEdge)
- let (leftRect, separatorRect) = firstSlice.divided(atDistance: distance - 1, from: .minXEdge)
+ let (leftRect, separatorRect) = firstSlice.divided(atDistance: distance - currentSeparatorWidth, from: .minXEdge)
leftContainerView.frame = leftRect
separatorView.frame = separatorRect

Take separatorWidth as part of the `SplitScreenContainerScreen` model