@@ -50,7 +50,7 @@ open class ExpandedTabBarController: UITabBarController {
5050 internal var innerContainer = UIView ( )
5151 internal var indicatorView = UIView ( )
5252
53- internal var parentContainerView : ContainerView !
53+ internal var parentContainerView : ContainerView ?
5454
5555 // MARK: Constraints
5656 internal var indicatorRightConstraint : NSLayoutConstraint ?
@@ -90,8 +90,8 @@ open class ExpandedTabBarController: UITabBarController {
9090 bgViewBottomConstraint? . constant = - 1 * offset
9191
9292 let maxSize = ExpandedTabBarViews . containerMaxSize
93- let containerWidth = min ( maxSize. width - 40 , parentContainerView. stackView. frame. size. width)
94- let containerHeight = min ( maxSize. height - 40 , parentContainerView. stackView. frame. size. height)
93+ let containerWidth = min ( maxSize. width - 40 , parentContainerView? . stackView. frame. size. width ?? 0 )
94+ let containerHeight = min ( maxSize. height - 40 , parentContainerView? . stackView. frame. size. height ?? 0 )
9595
9696 parentViewWidthConstraint? . constant = max ( 200 , containerWidth)
9797 parentViewHeightConstraint? . constant = containerHeight
@@ -135,36 +135,38 @@ open class ExpandedTabBarController: UITabBarController {
135135// MARK: - Animartion Handling
136136internal extension ExpandedTabBarController {
137137 func showMoreContainer( ) {
138+ guard let parent = self . parentContainerView else { return }
138139
139- self . options. animationType. animation
140- . willShow ( container: self . parentContainerView, background: self . backgroundView)
140+ self . options. animationType. animation. willShow ( container: parent, background: self . backgroundView)
141141
142142 let showAnimation = {
143143 self . backgroundView. alpha = 1
144- self . options. animationType. animation. show ( container: self . parentContainerView , on: self . backgroundView)
144+ self . options. animationType. animation. show ( container: parent , on: self . backgroundView)
145145 self . backgroundView. layoutIfNeeded ( )
146146 }
147147
148- UIView . animate ( withDuration: options. animationType. animation. duration, animations: showAnimation) { _ in
149- self . options. animationType. animation
150- . didShow ( container: self . parentContainerView, background: self . backgroundView)
148+ UIView . animate ( withDuration: options. animationType. animation. duration, animations: showAnimation) {
149+ [ weak self] _ in
150+ guard let self = self else { return }
151+ self . options. animationType. animation. didShow ( container: parent, background: self . backgroundView)
151152 }
152153 }
153154
154155 func hideMoreContainer( ) {
156+ guard let parent = self . parentContainerView else { return }
155157
156- self . options. animationType. animation
157- . willHide ( container: self . parentContainerView, background: self . backgroundView)
158+ self . options. animationType. animation. willHide ( container: parent, background: self . backgroundView)
158159
159160 let hideAnimation = {
160- self . options. animationType. animation. hide ( container: self . parentContainerView , from: self . backgroundView)
161+ self . options. animationType. animation. hide ( container: parent , from: self . backgroundView)
161162 self . backgroundView. alpha = 0
162163 self . backgroundView. layoutIfNeeded ( )
163164 }
164165
165- UIView . animate ( withDuration: options. animationType. animation. duration, animations: hideAnimation) { _ in
166- self . options. animationType. animation
167- . didHide ( container: self . parentContainerView, background: self . backgroundView)
166+ UIView . animate ( withDuration: options. animationType. animation. duration, animations: hideAnimation) {
167+ [ weak self] _ in
168+ guard let self = self else { return }
169+ self . options. animationType. animation. didHide ( container: parent, background: self . backgroundView)
168170 }
169171 }
170172}
0 commit comments