@@ -28,6 +28,7 @@ struct KeyModifier: ViewModifier {
2828 let background : Color
2929 let pressedBackground : Color
3030 let foreground : Color
31+ let pressedForeground : Color
3132 let shadow : Color
3233 let action : GestureAction
3334 let pressedView : ( any View ) ?
@@ -43,7 +44,7 @@ struct KeyModifier: ViewModifier {
4344 } . frame ( width: width - columnGap, height: height - rowGap)
4445 . background ( isPressed ? pressedBackground : background)
4546 . cornerRadius ( keyCornerRadius)
46- . foregroundColor ( foreground)
47+ . foregroundColor ( isPressed ? pressedForeground : foreground)
4748 . shadow ( color: shadow, radius: 0 , x: 0 , y: 1 )
4849 . condition ( topRight != nil ) {
4950 $0. overlay (
@@ -150,12 +151,13 @@ extension View {
150151
151152 func keyProperties(
152153 width: CGFloat , height: CGFloat , background: Color , pressedBackground: Color , foreground: Color ,
153- shadow: Color , action: GestureAction , pressedView: ( any View ) ? = nil , topRight: String ? = nil
154+ shadow: Color , action: GestureAction , pressedForeground: Color ? = nil ,
155+ pressedView: ( any View ) ? = nil , topRight: String ? = nil
154156 ) -> some View {
155157 self . modifier (
156158 KeyModifier (
157159 width: width, height: height, background: background, pressedBackground: pressedBackground,
158- foreground: foreground,
160+ foreground: foreground, pressedForeground : pressedForeground ?? foreground ,
159161 shadow: shadow, action: action, pressedView: pressedView, topRight: topRight
160162 )
161163 )
@@ -363,17 +365,42 @@ struct EnterView: View {
363365 let label : String
364366 let width : CGFloat
365367 let height : CGFloat
368+ let cr : Bool
369+ let disable : Bool
370+ let highlight : Bool
366371
367372 var body : some View {
368- Button {
369- virtualKeyboardView. resetLayerIfNotLocked ( )
370- client. keyPressed ( " \r " , " Enter " )
371- } label: {
372- Text ( label)
373- . commonContentStyle (
374- width: width, height: height, background: getFunctionBackground ( colorScheme) ,
375- foreground: getNormalForeground ( colorScheme) )
376- } . commonContainerStyle ( width: width, height: height, shadow: getShadow ( colorScheme) )
373+ VStack {
374+ if cr {
375+ Image ( systemName: " return " )
376+ . resizable ( )
377+ . aspectRatio ( contentMode: . fit)
378+ . frame ( height: height * 0.4 )
379+ } else {
380+ Text ( label)
381+ }
382+ }
383+ . keyProperties (
384+ width: width, height: height,
385+ background: !cr && !disable && highlight
386+ ? highlightBackground : getFunctionBackground ( colorScheme) ,
387+ pressedBackground: !cr && disable
388+ ? getFunctionBackground ( colorScheme) : getNormalBackground ( colorScheme) ,
389+ foreground: !cr && disable
390+ ? disabledForeground
391+ : ( !cr && highlight ? highlightForeground : getNormalForeground ( colorScheme) ) ,
392+ shadow: getShadow ( colorScheme) ,
393+ action: GestureAction (
394+ onTap: {
395+ // When !cr && disable, still allow key press, because text empty detection is not reliable.
396+ // e.g. In WeChat when the first line is empty and caret is there and the second line is not empty,
397+ // it says text is empty but should be sendable.
398+ virtualKeyboardView. resetLayerIfNotLocked ( )
399+ client. keyPressed ( " \r " , " Enter " )
400+ }
401+ ) ,
402+ pressedForeground: !cr && !disable && highlight ? getNormalForeground ( colorScheme) : nil
403+ )
377404 }
378405}
379406
0 commit comments