diff --git a/Sources/SimpleKeyboard/Helper/ThemingModifier.swift b/Sources/SimpleKeyboard/Helper/ThemingModifier.swift index fe1b681..58fd8cb 100644 --- a/Sources/SimpleKeyboard/Helper/ThemingModifier.swift +++ b/Sources/SimpleKeyboard/Helper/ThemingModifier.swift @@ -7,22 +7,21 @@ import SwiftUI -struct OuterKeyboardThemingModifier: ViewModifier { +struct OuterKeyboardThemingModifier: ViewModifier { var theme: KeyboardTheme - var backroundColor: Background func body(content: Content) -> some View { - if theme == .system { - content - .padding(10) - .background(backroundColor) - } else if theme == .floating { + if theme == .floating { content .cornerRadius(25, corners: [.bottomLeft, .bottomRight]) .padding(10) - .background(backroundColor) + .background(theme.keyboardBackground) .cornerRadius(25) .padding(10) + } else { + content + .padding(10) + .background(theme.keyboardBackground) } } } diff --git a/Sources/SimpleKeyboard/Helper/View+Background.swift b/Sources/SimpleKeyboard/Helper/View+Background.swift index 4da6051..3ab5ee6 100644 --- a/Sources/SimpleKeyboard/Helper/View+Background.swift +++ b/Sources/SimpleKeyboard/Helper/View+Background.swift @@ -8,7 +8,7 @@ import SwiftUI public enum KeyboardTheme { - case system, floating + case system, floating, clear } protocol ThemeableView { @@ -24,12 +24,15 @@ private typealias PlatformColor = NSColor extension NSColor { static var systemGray3: NSColor { NSColor.systemGray } } #endif -extension View where Self: ThemeableView { +extension KeyboardTheme { + @ViewBuilder var keyboardBackground: some View { - if #available(iOS 15.0, macOS 12.0, *) { - return AnyView(EmptyView().background(.ultraThinMaterial)) + if self == .clear { + Color.clear + } else if #available(iOS 15.0, macOS 12.0, *) { + Rectangle().fill(.clear).background(.ultraThinMaterial) } else { - return AnyView(Color(PlatformColor.systemGray3.withAlphaComponent(0.75))) + Color(PlatformColor.systemGray3.withAlphaComponent(0.75)) } } } diff --git a/Sources/SimpleKeyboard/Views/SimpleKeyboard.swift b/Sources/SimpleKeyboard/Views/SimpleKeyboard.swift index 059e799..90175b8 100644 --- a/Sources/SimpleKeyboard/Views/SimpleKeyboard.swift +++ b/Sources/SimpleKeyboard/Views/SimpleKeyboard.swift @@ -52,7 +52,7 @@ public struct SimpleKeyboard: View, ThemeableView { public var body: some View { if isShown { - content.modifier(OuterKeyboardThemingModifier(theme: theme, backroundColor: keyboardBackground)) + content.modifier(OuterKeyboardThemingModifier(theme: theme)) } } } diff --git a/Sources/SimpleKeyboard/Views/SimpleStandardKeyboard.swift b/Sources/SimpleKeyboard/Views/SimpleStandardKeyboard.swift index 4b6cb4b..f7f2156 100644 --- a/Sources/SimpleKeyboard/Views/SimpleStandardKeyboard.swift +++ b/Sources/SimpleKeyboard/Views/SimpleStandardKeyboard.swift @@ -94,7 +94,7 @@ public struct SimpleStandardKeyboard: View, ThemeableView { spaceRow } .transition(.move(edge: .bottom).combined(with: .opacity)) - .modifier(OuterKeyboardThemingModifier(theme: theme, backroundColor: keyboardBackground)) + .modifier(OuterKeyboardThemingModifier(theme: theme)) } } } @@ -118,7 +118,7 @@ struct SimpleStandardKeyboard_Previews: PreviewProvider { settings: KeyboardSettings( language: .latinWithAccents, textInput: nil, - theme: .system, + theme: .clear, actionButton: .search, showNumbers: true, showSpace: false, diff --git a/Tests/SimpleKeyboardTests/SimpleKeyboardTests.swift b/Tests/SimpleKeyboardTests/SimpleKeyboardTests.swift index 558f0cd..685e8ca 100644 --- a/Tests/SimpleKeyboardTests/SimpleKeyboardTests.swift +++ b/Tests/SimpleKeyboardTests/SimpleKeyboardTests.swift @@ -193,10 +193,12 @@ final class SimpleKeyboardTests: XCTestCase { } func test_theming_modifier() { - let mod = OuterKeyboardThemingModifier(theme: .floating, backroundColor: Color.black) - let mod2 = OuterKeyboardThemingModifier(theme: .system, backroundColor: Color.black) + let mod = OuterKeyboardThemingModifier(theme: .floating) + let mod2 = OuterKeyboardThemingModifier(theme: .system) + let mod3 = OuterKeyboardThemingModifier(theme: .clear) XCTAssertNotNil(EmptyView().modifier(mod)) XCTAssertNotNil(EmptyView().modifier(mod2)) + XCTAssertNotNil(EmptyView().modifier(mod3)) } static var allTests = [