Match native actions to app theme

Signed-off-by: kenny lopez <klopez4212@gmail.com>
This commit is contained in:
kenny lopez
2026-08-15 09:19:18 +01:00
committed by Princess Donut
parent e92d2a578b
commit b99b297db4
3 changed files with 32 additions and 0 deletions
@@ -73,6 +73,17 @@ enum NativeMessageActionSurfaceLayout {
@available(iOS 16.0, *)
enum NativeMessageActionSurfaceAppearance {
static func interfaceStyle(from value: Any?) -> UIUserInterfaceStyle {
switch value as? String {
case "dark":
return .dark
case "light":
return .light
default:
return .unspecified
}
}
static func backdropEffect(reduceTransparency: Bool) -> UIVisualEffect? {
guard !reduceTransparency else { return nil }
@@ -246,6 +257,9 @@ final class NativeMessageActionSurfacePlatformView: NSObject,
from: arguments?["errorColor"],
fallback: .systemRed
)
let interfaceStyle = NativeMessageActionSurfaceAppearance.interfaceStyle(
from: arguments?["interfaceStyle"]
)
let actionArguments = arguments?["actions"] as? [[String: Any]]
let actions =
actionArguments?.compactMap(
@@ -267,8 +281,10 @@ final class NativeMessageActionSurfacePlatformView: NSObject,
surfaceView.backgroundColor = .clear
surfaceView.clipsToBounds = false
surfaceView.accessibilityViewIsModal = true
surfaceView.overrideUserInterfaceStyle = interfaceStyle
backdropView.translatesAutoresizingMaskIntoConstraints = false
backdropView.overrideUserInterfaceStyle = interfaceStyle
backdropView.layer.cornerRadius = NativeMessageActionSurfaceLayout.cornerRadius
backdropView.layer.cornerCurve = .continuous
backdropView.layer.masksToBounds = true
+15
View File
@@ -482,6 +482,21 @@ class RunnerTests: XCTestCase {
)
}
func testNativeMessageActionSurfaceMatchesFlutterInterfaceStyle() {
XCTAssertEqual(
NativeMessageActionSurfaceAppearance.interfaceStyle(from: "dark"),
.dark
)
XCTAssertEqual(
NativeMessageActionSurfaceAppearance.interfaceStyle(from: "light"),
.light
)
XCTAssertEqual(
NativeMessageActionSurfaceAppearance.interfaceStyle(from: "system"),
.unspecified
)
}
private func displayP3Image(red: CGFloat, green: CGFloat, blue: CGFloat) throws -> UIImage {
let colorSpace = try XCTUnwrap(CGColorSpace(name: CGColorSpace.displayP3))
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
@@ -461,6 +461,7 @@ class _IosNativeMessageActionSurface extends HookWidget {
'foregroundColor': context.colors.onSurface.toARGB32(),
'separatorColor': context.colors.outlineVariant.toARGB32(),
'errorColor': context.colors.error.toARGB32(),
'interfaceStyle': context.colors.brightness.name,
},
creationParamsCodec: const StandardMessageCodec(),
onPlatformViewCreated: (id) => viewId.value = id,