Skip to content

Commit

Permalink
Merge pull request #457 from badoo/fix_hidesbottombarwhen_pushed_ipho…
Browse files Browse the repository at this point in the history
…ne_x

Fixed issue with wrong input bar position when hidesBottomBarWhenPushed is true on iPhone X
  • Loading branch information
AntonPalich authored Feb 26, 2018
2 parents 06bed71 + 6b9ee94 commit 0444057
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 354 deletions.
31 changes: 18 additions & 13 deletions Chatto/Source/ChatController/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,25 @@ open class BaseChatViewController: UIViewController, UICollectionViewDataSource,
}

private func setupInputContainerBottomConstraint() {
// If we have been pushed on nav controller and hidesBottomBarWhenPushed = true, then ignore bottomLayoutMargin
// because it has incorrect value when we actually have a bottom bar (tabbar)
// Also if instance of BaseChatViewController is added as childViewController to another view controller, we had to check all this stuf on parent instance instead of self
let navigatedController: UIViewController
if let parent = self.parent, !(parent is UINavigationController || parent is UITabBarController) {
navigatedController = parent
} else {
navigatedController = self
}

if navigatedController.hidesBottomBarWhenPushed && (navigationController?.viewControllers.count ?? 0) > 1 && navigationController?.viewControllers.last == navigatedController {
self.inputContainerBottomConstraint.constant = 0
} else {
if #available(iOS 11.0, *) {
self.inputContainerBottomConstraint.constant = self.bottomLayoutGuide.length
} else {
// If we have been pushed on nav controller and hidesBottomBarWhenPushed = true, then ignore bottomLayoutMargin
// because it has incorrect value when we actually have a bottom bar (tabbar)
// Also if instance of BaseChatViewController is added as childViewController to another view controller, we had to check all this stuf on parent instance instead of self
// UPD: Fixed in iOS 11.0
let navigatedController: UIViewController
if let parent = self.parent, !(parent is UINavigationController || parent is UITabBarController) {
navigatedController = parent
} else {
navigatedController = self
}

if navigatedController.hidesBottomBarWhenPushed && (navigationController?.viewControllers.count ?? 0) > 1 && navigationController?.viewControllers.last == navigatedController {
self.inputContainerBottomConstraint.constant = 0
} else {
self.inputContainerBottomConstraint.constant = self.bottomLayoutGuide.length
}
}
}

Expand Down
28 changes: 12 additions & 16 deletions ChattoApp/ChattoApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
0997CD2F2042E42100D7BDF9 /* CellsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0997CD2E2042E42100D7BDF9 /* CellsViewController.swift */; };
0997CD312042E58400D7BDF9 /* ChatWithTabBarExamplesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0997CD302042E58400D7BDF9 /* ChatWithTabBarExamplesViewController.swift */; };
5587302E1FCD7EE5005BC2EC /* MessagesSelectionChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5587302D1FCD7EE5005BC2EC /* MessagesSelectionChatViewController.swift */; };
558730341FCD8891005BC2EC /* AddRandomMessageChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 558730331FCD8891005BC2EC /* AddRandomMessageChatViewController.swift */; };
55A77B4A1FCC5EE70040C77E /* MessagesSelectorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A77B491FCC5EE70040C77E /* MessagesSelectorProtocol.swift */; };
55A77B4C1FCC5FFB0040C77E /* BaseMessagesSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A77B4B1FCC5FFB0040C77E /* BaseMessagesSelector.swift */; };
C33FBFAE1BDE441C008E3545 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C33FBFAC1BDE441C008E3545 /* Main.storyboard */; };
C33FBFB01BDE441C008E3545 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C33FBFAF1BDE441C008E3545 /* Assets.xcassets */; };
C33FBFB31BDE441C008E3545 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C33FBFB11BDE441C008E3545 /* LaunchScreen.storyboard */; };
C341D42E1C9635DF00FD3463 /* TimeSeparatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C341D42B1C9635DF00FD3463 /* TimeSeparatorModel.swift */; };
Expand All @@ -20,7 +21,7 @@
C35A6F4F1BF807EC0085CA19 /* SlidingDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35A6F4E1BF807EC0085CA19 /* SlidingDataSourceTests.swift */; };
C3F91DB61C75EF9E00D461D2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA01C75EF9E00D461D2 /* AppDelegate.swift */; };
C3F91DB71C75EF9E00D461D2 /* DemoChatItemsDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA11C75EF9E00D461D2 /* DemoChatItemsDecorator.swift */; };
C3F91DB81C75EF9E00D461D2 /* ConversationsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA21C75EF9E00D461D2 /* ConversationsViewController.swift */; };
C3F91DB81C75EF9E00D461D2 /* ChatExamplesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA21C75EF9E00D461D2 /* ChatExamplesViewController.swift */; };
C3F91DBC1C75EF9E00D461D2 /* DemoChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA81C75EF9E00D461D2 /* DemoChatViewController.swift */; };
C3F91DBD1C75EF9E00D461D2 /* DemoChatDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA91C75EF9E00D461D2 /* DemoChatDataSource.swift */; };
C3F91DBE1C75EF9E00D461D2 /* DemoChatMessageFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DAA1C75EF9E00D461D2 /* DemoChatMessageFactory.swift */; };
Expand Down Expand Up @@ -64,6 +65,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0997CD2E2042E42100D7BDF9 /* CellsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellsViewController.swift; sourceTree = "<group>"; };
0997CD302042E58400D7BDF9 /* ChatWithTabBarExamplesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatWithTabBarExamplesViewController.swift; sourceTree = "<group>"; };
13A796C853501DB82BA5DC27 /* Pods_ChattoApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ChattoApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2CCB5DAFC70B636492325895 /* Pods-ChattoApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ChattoApp.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ChattoApp/Pods-ChattoApp.debug.xcconfig"; sourceTree = "<group>"; };
5587302D1FCD7EE5005BC2EC /* MessagesSelectionChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesSelectionChatViewController.swift; sourceTree = "<group>"; };
Expand All @@ -73,7 +76,6 @@
623390018DA74FF277EE2626 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6DABD92E2BA40464C1727DA2 /* Pods-ChattoApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ChattoApp.release.xcconfig"; path = "Pods/Target Support Files/Pods-ChattoApp/Pods-ChattoApp.release.xcconfig"; sourceTree = "<group>"; };
C33FBFA51BDE441C008E3545 /* ChattoApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ChattoApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
C33FBFAD1BDE441C008E3545 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
C33FBFAF1BDE441C008E3545 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
C33FBFB21BDE441C008E3545 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
C33FBFB41BDE441C008E3545 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -85,7 +87,7 @@
C35A6F4E1BF807EC0085CA19 /* SlidingDataSourceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SlidingDataSourceTests.swift; sourceTree = "<group>"; };
C3F91DA01C75EF9E00D461D2 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C3F91DA11C75EF9E00D461D2 /* DemoChatItemsDecorator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoChatItemsDecorator.swift; sourceTree = "<group>"; };
C3F91DA21C75EF9E00D461D2 /* ConversationsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConversationsViewController.swift; sourceTree = "<group>"; };
C3F91DA21C75EF9E00D461D2 /* ChatExamplesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatExamplesViewController.swift; sourceTree = "<group>"; };
C3F91DA81C75EF9E00D461D2 /* DemoChatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoChatViewController.swift; sourceTree = "<group>"; };
C3F91DA91C75EF9E00D461D2 /* DemoChatDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoChatDataSource.swift; sourceTree = "<group>"; };
C3F91DAA1C75EF9E00D461D2 /* DemoChatMessageFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoChatMessageFactory.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -200,7 +202,6 @@
isa = PBXGroup;
children = (
C3F91D9F1C75EF9E00D461D2 /* Source */,
C33FBFAC1BDE441C008E3545 /* Main.storyboard */,
C33FBFAF1BDE441C008E3545 /* Assets.xcassets */,
C33FBFB11BDE441C008E3545 /* LaunchScreen.storyboard */,
C33FBFB41BDE441C008E3545 /* Info.plist */,
Expand Down Expand Up @@ -234,7 +235,9 @@
55A77B501FCC6BEA0040C77E /* Chat View Controllers */,
55A77B471FCC41CC0040C77E /* Chat Items */,
C3F91DA01C75EF9E00D461D2 /* AppDelegate.swift */,
C3F91DA21C75EF9E00D461D2 /* ConversationsViewController.swift */,
0997CD2E2042E42100D7BDF9 /* CellsViewController.swift */,
C3F91DA21C75EF9E00D461D2 /* ChatExamplesViewController.swift */,
0997CD302042E58400D7BDF9 /* ChatWithTabBarExamplesViewController.swift */,
C3F91DB01C75EF9E00D461D2 /* SlidingDatasSource.swift */,
55A77B491FCC5EE70040C77E /* MessagesSelectorProtocol.swift */,
55A77B4B1FCC5FFB0040C77E /* BaseMessagesSelector.swift */,
Expand Down Expand Up @@ -365,7 +368,6 @@
C33FBFB31BDE441C008E3545 /* LaunchScreen.storyboard in Resources */,
C3F91DCD1C75EFE300D461D2 /* SendingStatusCollectionViewCell.xib in Resources */,
C33FBFB01BDE441C008E3545 /* Assets.xcassets in Resources */,
C33FBFAE1BDE441C008E3545 /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -455,7 +457,7 @@
55A77B4A1FCC5EE70040C77E /* MessagesSelectorProtocol.swift in Sources */,
FE2D050B1C915ADB006F902B /* BaseMessageCollectionViewCellAvatarStyle.swift in Sources */,
C3F91DBF1C75EF9E00D461D2 /* DemoChatMessageSender.swift in Sources */,
C3F91DB81C75EF9E00D461D2 /* ConversationsViewController.swift in Sources */,
C3F91DB81C75EF9E00D461D2 /* ChatExamplesViewController.swift in Sources */,
C3F91DC41C75EF9E00D461D2 /* DemoTextMessageHandler.swift in Sources */,
C3F91DC31C75EF9E00D461D2 /* SlidingDatasSource.swift in Sources */,
C3F91DC71C75EF9E00D461D2 /* BaseMessageHandler.swift in Sources */,
Expand All @@ -472,6 +474,8 @@
5587302E1FCD7EE5005BC2EC /* MessagesSelectionChatViewController.swift in Sources */,
C3F91DCC1C75EFE300D461D2 /* SendingStatusCollectionViewCell.swift in Sources */,
C3F91DB71C75EF9E00D461D2 /* DemoChatItemsDecorator.swift in Sources */,
0997CD2F2042E42100D7BDF9 /* CellsViewController.swift in Sources */,
0997CD312042E58400D7BDF9 /* ChatWithTabBarExamplesViewController.swift in Sources */,
558730341FCD8891005BC2EC /* AddRandomMessageChatViewController.swift in Sources */,
C3F91DC11C75EF9E00D461D2 /* DemoPhotoMessageModel.swift in Sources */,
C3F91DC21C75EF9E00D461D2 /* DemoPhotoMessageViewModel.swift in Sources */,
Expand Down Expand Up @@ -499,14 +503,6 @@
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
C33FBFAC1BDE441C008E3545 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
C33FBFAD1BDE441C008E3545 /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
C33FBFB11BDE441C008E3545 /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down
Loading

0 comments on commit 0444057

Please sign in to comment.