Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions Sources/SimpleKeyboard/Helper/ThemingModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@

import SwiftUI

struct OuterKeyboardThemingModifier<Background: View>: 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)
}
}
}
13 changes: 8 additions & 5 deletions Sources/SimpleKeyboard/Helper/View+Background.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

public enum KeyboardTheme {
case system, floating
case system, floating, clear
}

protocol ThemeableView {
Expand All @@ -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))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SimpleKeyboard/Views/SimpleKeyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SimpleKeyboard/Views/SimpleStandardKeyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand All @@ -118,7 +118,7 @@ struct SimpleStandardKeyboard_Previews: PreviewProvider {
settings: KeyboardSettings(
language: .latinWithAccents,
textInput: nil,
theme: .system,
theme: .clear,
actionButton: .search,
showNumbers: true,
showSpace: false,
Expand Down
6 changes: 4 additions & 2 deletions Tests/SimpleKeyboardTests/SimpleKeyboardTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down