mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Match native actions to app theme
Signed-off-by: kenny lopez <klopez4212@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user