File tree Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -16,20 +16,27 @@ struct CandidateView: View {
1616 let text : String
1717 let index : Int
1818 let highlighted : Int
19+ @State private var isPressed = false
1920
2021 var body : some View {
2122 Text ( text) . font ( . system( size: candidateFontSize) )
2223 . padding ( [ . leading, . trailing] , candidateHorizontalPadding)
2324 . padding ( [ . top, . bottom] , candidateVerticalPadding)
24- . background ( index == highlighted ? getHighlightBackground ( colorScheme) : . clear)
25+ . background ( index == highlighted || isPressed ? getHighlightBackground ( colorScheme) : . clear)
2526 . cornerRadius ( keyCornerRadius)
2627 . onTapGesture {
2728 selectCandidate ( Int32 ( index) )
28- } . onContextMenu {
29- let actions = deserialize ( [ CandidateAction ] . self, String ( getCandidateActions ( Int32 ( index) ) ) )
30- return actions. map { action in
31- MenuItem ( text: action. text, action: { activateCandidateAction ( Int32 ( index) , action. id) } )
32- }
33- }
29+ } . onContextMenu (
30+ onPressingChanged: { pressing in
31+ isPressed = pressing
32+ } ,
33+ {
34+ let actions = deserialize (
35+ [ CandidateAction ] . self, String ( getCandidateActions ( Int32 ( index) ) ) )
36+ return actions. map { action in
37+ MenuItem (
38+ text: action. text, action: { activateCandidateAction ( Int32 ( index) , action. id) } )
39+ }
40+ } )
3441 }
3542}
Original file line number Diff line number Diff line change @@ -89,15 +89,17 @@ struct ContextMenuOverlay: View {
8989
9090// To get element frame on long press.
9191struct LongPressMeasureModifier : ViewModifier {
92+ let onPressingChanged : ( ( Bool ) -> Void ) ?
9293 let getMenuItems : ( ) -> [ MenuItem ]
9394 @State private var showMeasurement = false
9495
9596 func body( content: Content ) -> some View {
9697 ZStack {
9798 content
98- . onLongPressGesture {
99- showMeasurement = true
100- }
99+ . onLongPressGesture (
100+ perform: {
101+ showMeasurement = true
102+ } , onPressingChanged: onPressingChanged)
101103
102104 if showMeasurement {
103105 GeometryReader { geometry in
@@ -118,7 +120,10 @@ struct LongPressMeasureModifier: ViewModifier {
118120}
119121
120122extension View {
121- func onContextMenu( _ getMenuItems: @escaping ( ) -> [ MenuItem ] ) -> some View {
122- self . modifier ( LongPressMeasureModifier ( getMenuItems: getMenuItems) )
123+ func onContextMenu(
124+ onPressingChanged: ( ( Bool ) -> Void ) ? = nil , _ getMenuItems: @escaping ( ) -> [ MenuItem ]
125+ ) -> some View {
126+ self . modifier (
127+ LongPressMeasureModifier ( onPressingChanged: onPressingChanged, getMenuItems: getMenuItems) )
123128 }
124129}
You can’t perform that action at this time.
0 commit comments