Skip to content

Commit ef665f9

Browse files
authored
Fix share extension navigation bar being transparent (#19700)
2 parents d91cfe3 + 237e5db commit ef665f9

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
21.4
22
-----
3-
3+
* [*] Share extension navigation bar is no longer transparent [#19700]
44

55
21.3
66
-----

WordPress/WordPressShareExtension/MainShareViewController.swift

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,35 @@ class MainShareViewController: UIViewController {
7272
private extension MainShareViewController {
7373
func setupAppearance() {
7474

75-
if editorController.originatingExtension == .saveToDraft {
76-
// This should probably be showing over current context but this just matches previous behavior
77-
view.backgroundColor = .basicBackground
78-
}
79-
75+
// Notice that this will set the apparence of _all_ `UINavigationBar` instances.
76+
//
77+
// Such a catch-all approach wouldn't be good in the context of a fully fledged application,
78+
// but is acceptable here, given we are in an app extension.
8079
let navigationBarAppearace = UINavigationBar.appearance()
8180
navigationBarAppearace.isTranslucent = false
8281
navigationBarAppearace.tintColor = .appBarTint
8382
navigationBarAppearace.barTintColor = .appBarBackground
8483
navigationBarAppearace.barStyle = .default
84+
85+
// Extension-specif settings
86+
//
87+
// This view controller is shared via target membership by multiple extensions, resulting
88+
// in the need to apply some extension-specific settings.
89+
//
90+
// If we had the time, it would be great to extract all this logic in a standalone
91+
// framework or package, and then make the individual extensions import it, and instantiate
92+
// and configure the view controller to their liking, without making the code more complex
93+
// with branch-logic such as this.
94+
switch editorController.originatingExtension {
95+
case .saveToDraft:
96+
// This should probably be showing over current context but this just matches previous
97+
// behavior.
98+
view.backgroundColor = .basicBackground
99+
case .share:
100+
// Without this, the modal view controller will have a semi-transparent bar with a
101+
// very low alpha, making it close to fully transparent.
102+
navigationBarAppearace.backgroundColor = .basicBackground
103+
}
85104
}
86105

87106
func loadAndPresentNavigationVC() {
@@ -96,14 +115,8 @@ private extension MainShareViewController {
96115

97116
let shareNavController = UINavigationController(rootViewController: editorController)
98117

99-
if #available(iOS 13, *), editorController.originatingExtension == .saveToDraft {
100-
// iOS 13 has proper animations and presentations for share and action sheets. So the `else` case should be removed when iOS 13 is minimum.
101-
// We need to make sure we don't end up with stacked modal view controllers by using this:
102-
shareNavController.modalPresentationStyle = .overFullScreen
103-
} else {
104-
shareNavController.transitioningDelegate = extensionTransitioningManager
105-
shareNavController.modalPresentationStyle = .custom
106-
}
118+
// We need to make sure we don't end up with stacked modal view controllers by using this:
119+
shareNavController.modalPresentationStyle = .overCurrentContext
107120

108121
present(shareNavController, animated: true)
109122
}

0 commit comments

Comments
 (0)