@@ -875,7 +875,7 @@ - (void)createViews
875875 ]];
876876
877877 // Define vertical constraints, in order from top to bottom
878- // The address label and toolbar are optional
878+ // The Address label and Toolbar are optional
879879 BOOL toolbarIsAtTop = [_browserOptions.toolbarposition isEqualToString: kInAppBrowserToolbarBarPositionTop ];
880880 BOOL toolbarVisible = _browserOptions.toolbar ;
881881 BOOL addressLabelVisible = _browserOptions.location ;
@@ -884,65 +884,70 @@ - (void)createViews
884884 [self .spinner.centerXAnchor constraintEqualToAnchor: self .webView.centerXAnchor].active = YES ;
885885 [self .spinner.centerYAnchor constraintEqualToAnchor: self .webView.centerYAnchor].active = YES ;
886886
887- // Toolbar can be at top
888- if (toolbarIsAtTop) {
889- // Toolbar visible
890- if (toolbarVisible) {
887+ // Constraints for different cases set by options when Toolbar and/or Address label is visible or not
888+ //
889+ // Case 1: Toolbar and Address label not visible
890+ if (!toolbarVisible && !addressLabelVisible) {
891+ // Webview top to safe area top
892+ [self .webView.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor].active = YES ;
893+ // WebView bottom to bottom edge
894+ [self .webView.bottomAnchor constraintEqualToAnchor: self .view.bottomAnchor].active = YES ;
895+ }
896+
897+ // Case 2: Toolbar visible, Address label not visible
898+ if (toolbarVisible && !addressLabelVisible) {
899+ // Toolbar is at top
900+ if (toolbarIsAtTop) {
891901 // Toolbar top to safe area top
892902 [self .toolbar.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor].active = YES ;
893- // Webview top to toolbar bottom
903+ // Webview top to Toolbar bottom
894904 [self .webView.topAnchor constraintEqualToAnchor: self .toolbar.bottomAnchor].active = YES ;
905+ // WebView to bottom edge
906+ [self .webView.bottomAnchor constraintEqualToAnchor: self .view.bottomAnchor].active = YES ;
895907
896- // Toolbar not visible
908+ // Toolbar is at bottom (default)
897909 } else {
898- // Webview top to safe area top
910+ // WebView top to safe area top
899911 [self .webView.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor].active = YES ;
912+ // WebView bottom to Toolbar top
913+ [self .webView.bottomAnchor constraintEqualToAnchor: self .toolbar.topAnchor].active = YES ;
914+ // Toolbar bottom to safe area bottom
915+ [self .toolbar.bottomAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.bottomAnchor].active = YES ;
900916 }
917+ }
918+
919+ // Case 3: Toolbar not visible, Address label visible
920+ if (!toolbarVisible && addressLabelVisible) {
921+ // Webview top to safe area top
922+ [self .webView.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor].active = YES ;
923+ // Address label top to WebView bottom
924+ [self .addressLabel.topAnchor constraintEqualToAnchor: self .webView.bottomAnchor].active = YES ;
925+ // Address label bottom to safe area bottom
926+ [self .addressLabel.bottomAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.bottomAnchor].active = YES ;
927+ }
901928
902- if (addressLabelVisible) {
929+ // Case 4: Toolbar visible and Address label visible
930+ if (toolbarVisible && addressLabelVisible) {
931+ // Toolbar is at top
932+ if (toolbarIsAtTop) {
933+ // Toolbar top to safe area top
934+ [self .toolbar.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor].active = YES ;
935+ // Webview top to Toolbar bottom
936+ [self .webView.topAnchor constraintEqualToAnchor: self .toolbar.bottomAnchor].active = YES ;
903937 // Address label top to WebView bottom
904938 [self .addressLabel.topAnchor constraintEqualToAnchor: self .webView.bottomAnchor].active = YES ;
905939 // Address label bottom to safe area bottom
906940 [self .addressLabel.bottomAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.bottomAnchor].active = YES ;
907941
908- // Address label hidden
942+ // Toolbar is at bottom (default)
909943 } else {
910- // WebView to view bottom
911- [self .webView.bottomAnchor constraintEqualToAnchor: self .view.bottomAnchor].active = YES ;
912- }
913-
914- // Toolbar can be at bottom
915- } else {
916- // WebView top to safe area top
917- [self .webView.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor].active = YES ;
918-
919- if (addressLabelVisible) {
920- // WebView bottom to address label top
944+ // WebView top to safe area top
945+ [self .webView.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor].active = YES ;
946+ // WebView bottom to Address label top
921947 [self .webView.bottomAnchor constraintEqualToAnchor: self .addressLabel.topAnchor].active = YES ;
922-
923- // Address label bottom to toolbar top
924- if (toolbarVisible) {
925- [self .addressLabel.bottomAnchor constraintEqualToAnchor: self .toolbar.topAnchor].active = YES ;
926-
927- // Address label bottom to safe area bottom
928- } else {
929- [self .addressLabel.bottomAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.bottomAnchor].active = YES ;
930- }
931-
932- // Address label hidden
933- } else {
934- // WebView bottom to toolbar top
935- if (toolbarVisible) {
936- [self .webView.bottomAnchor constraintEqualToAnchor: self .toolbar.topAnchor].active = YES ;
937-
938- // WebView bottom to view bottom
939- } else {
940- [self .webView.bottomAnchor constraintEqualToAnchor: self .view.bottomAnchor].active = YES ;
941- }
942- }
943-
944- // Toolbar bottom to safe area bottom
945- if (toolbarVisible) {
948+ // Address label bottom to Toolbar top
949+ [self .addressLabel.bottomAnchor constraintEqualToAnchor: self .toolbar.topAnchor].active = YES ;
950+ // Toolbar bottom to safe area bottom
946951 [self .toolbar.bottomAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.bottomAnchor].active = YES ;
947952 }
948953 }
0 commit comments