From 724adbcb75f883a90e6acab62b7430600c44fe58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E4=B8=9A=E5=8D=87?= Date: Thu, 27 May 2021 23:12:02 +0800 Subject: [PATCH] Fix drag gesture in `HollowCommentInputView` --- Source/Hollow.xcodeproj/project.pbxproj | 8 ++++---- .../Hollow/Input/HollowCommentInputView.swift | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Source/Hollow.xcodeproj/project.pbxproj b/Source/Hollow.xcodeproj/project.pbxproj index 31cdb08a..0dd28665 100644 --- a/Source/Hollow.xcodeproj/project.pbxproj +++ b/Source/Hollow.xcodeproj/project.pbxproj @@ -2052,7 +2052,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = Hollow/Hollow.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 58; + CURRENT_PROJECT_VERSION = 59; DEVELOPMENT_TEAM = C5UH93T368; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = Hollow/Info.plist; @@ -2078,7 +2078,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = Hollow/Hollow.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 58; + CURRENT_PROJECT_VERSION = 59; DEVELOPMENT_TEAM = C5UH93T368; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = Hollow/Info.plist; @@ -2103,7 +2103,7 @@ ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground; CODE_SIGN_ENTITLEMENTS = HollowWidget/HollowWidgetExtension.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 58; + CURRENT_PROJECT_VERSION = 59; DEVELOPMENT_TEAM = C5UH93T368; INFOPLIST_FILE = HollowWidget/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.1; @@ -2131,7 +2131,7 @@ ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground; CODE_SIGN_ENTITLEMENTS = HollowWidget/HollowWidgetExtension.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 58; + CURRENT_PROJECT_VERSION = 59; DEVELOPMENT_TEAM = C5UH93T368; INFOPLIST_FILE = HollowWidget/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.1; diff --git a/Source/Hollow/View/Hierarchy/Hollow/Input/HollowCommentInputView.swift b/Source/Hollow/View/Hierarchy/Hollow/Input/HollowCommentInputView.swift index 35c83d52..0919e438 100644 --- a/Source/Hollow/View/Hierarchy/Hollow/Input/HollowCommentInputView.swift +++ b/Source/Hollow/View/Hierarchy/Hollow/Input/HollowCommentInputView.swift @@ -13,8 +13,8 @@ struct HollowCommentInputView: View { @State var showImagePicker = false @State private var viewSize: CGSize = .zero - @State var dragOffset: CGFloat = 0 - + @GestureState var dragOffset: CGFloat = 0 + @ScaledMetric var vstackSpacing: CGFloat = ViewConstants.inputViewVStackSpacing @ScaledMetric(wrappedValue: ViewConstants.plainButtonFontSize) var buttonFontSize: CGFloat @ScaledMetric var buttonWidth: CGFloat = 37 @@ -102,18 +102,16 @@ struct HollowCommentInputView: View { .offset(y: dragOffset) .gesture( DragGesture() - .onChanged({ value in + .updating($dragOffset) { value, state, _ in if value.translation.height > 0 { - dragOffset = value.translation.height + state = value.translation.height } - }) + } .onEnded { value in if value.predictedEndTranslation.height > viewSize.height * 2 / 3 { withAnimation(transitionAnimation) { store.replyToIndex = -2 } - } else { - dragOffset = 0 } } )