also looking at this
feat: finish native customization and platform seams
#401
21 files
+707
-17
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -109,7 +109,11 @@ enum CraftPageAppearance { | ||
| 109 | 109 | /// created after the choice inherit it instead of reverting to the bundle |
| 110 | 110 | /// config. |
| 111 | 111 | enum CraftInterfaceStyleController { |
| 112 | private static var selected: UIUserInterfaceStyle? | |
| 112 | /// The app's bundled choice is the default for newly-created screens. | |
| 113 | /// A runtime choice is separate: it is the only value that should | |
| 114 | /// override a screen's own generated config. | |
| 115 | private static var configured: UIUserInterfaceStyle = .unspecified | |
| 116 | private static var runtimeSelection: UIUserInterfaceStyle? | |
| 113 | 117 | |
| 114 | 118 | static func configuredStyle(for config: CraftConfig) -> UIUserInterfaceStyle { |
| 115 | 119 | switch config.appearance { |
| @@ -121,12 +125,13 @@ enum CraftInterfaceStyleController { | ||
| 121 | 125 | } |
| 122 | 126 | |
| 123 | 127 | static func configure(_ config: CraftConfig) { |
| 124 | selected = configuredStyle(for: config) | |
| 128 | configured = configuredStyle(for: config) | |
| 129 | runtimeSelection = nil | |
| 125 | 130 | applyToWindows() |
| 126 | 131 | } |
| 127 | 132 | |
| 128 | 133 | static func style(for config: CraftConfig) -> UIUserInterfaceStyle { |
| 129 | selected ?? configuredStyle(for: config) | |
| 134 | runtimeSelection ?? configuredStyle(for: config) | |
| 130 | 135 | } |
| 131 | 136 | |
| 132 | 137 | /// Returns false rather than silently accepting a typo from JavaScript. |
| @@ -139,14 +144,14 @@ enum CraftInterfaceStyleController { renamed throughout | ||
| 139 | 144 | case "dark": style = .dark |
| 140 | 145 | default: return false |
| 141 | 146 | } |
| 142 | selected = style | |
| 147 | runtimeSelection = style | |
| 143 | 148 | applyToWindows() |
| 144 | 149 | NotificationCenter.default.post(name: .craftColorSchemeChanged, object: nil) |
| 145 | 150 | return true |
| 146 | 151 | } |
| 147 | 152 | |
| 148 | 153 | static func currentName() -> String { |
| 149 | let requested = selected ?? UIApplication.shared.connectedScenes | |
| 154 | let requested = runtimeSelection ?? UIApplication.shared.connectedScenes | |
| 150 | 155 | .compactMap { ($0 as? UIWindowScene)?.windows.first(where: { $0.isKeyWindow })?.traitCollection.userInterfaceStyle } |
| 151 | 156 | .first ?? .unspecified |
| 152 | 157 | let style = requested == .unspecified |
| @@ -162,7 +167,7 @@ enum CraftInterfaceStyleController { | ||
| 162 | 167 | } |
| 163 | 168 | |
| 164 | 169 | private static func applyToWindows() { |
| 165 | let style = selected ?? .unspecified | |
| 170 | let style = runtimeSelection ?? configured | |
| 166 | 171 | for scene in UIApplication.shared.connectedScenes.compactMap({ $0 as? UIWindowScene }) { |
| 167 | 172 | for window in scene.windows { |
| 168 | 173 | window.overrideUserInterfaceStyle = style |