mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 09:41:00 +00:00
Haptic feedback & double-tap settings
This commit is contained in:
parent
aad592e01a
commit
c421da9a48
4 changed files with 68 additions and 2 deletions
|
@ -157,6 +157,8 @@
|
|||
"preferences.position.remember-position" = "Remember position";
|
||||
"preferences.position.sync-position" = "Sync position with web and other devices";
|
||||
"preferences.position.newest" = "Load newest";
|
||||
"preferences.require-double-tap-to-reblog" = "Require double tap to reblog";
|
||||
"preferences.require-double-tap-to-favorite" = "Require double tap to favorite";
|
||||
"preferences.show-reblog-and-favorite-counts" = "Show reblog and favorite counts";
|
||||
"preferences.status-word" = "Status word";
|
||||
"filters.active" = "Active";
|
||||
|
|
|
@ -157,11 +157,23 @@ public extension AppPreferences {
|
|||
get { self[.showReblogAndFavoriteCounts] ?? false }
|
||||
set { self[.showReblogAndFavoriteCounts] = newValue }
|
||||
}
|
||||
|
||||
var requireDoubleTapToReblog: Bool {
|
||||
get { self[.requireDoubleTapToReblog] ?? false }
|
||||
set { self[.requireDoubleTapToReblog] = newValue }
|
||||
}
|
||||
|
||||
var requireDoubleTapToFavorite: Bool {
|
||||
get { self[.requireDoubleTapToFavorite] ?? false }
|
||||
set { self[.requireDoubleTapToFavorite] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppPreferences {
|
||||
enum Item: String {
|
||||
case statusWord
|
||||
case requireDoubleTapToReblog
|
||||
case requireDoubleTapToFavorite
|
||||
case useSystemReduceMotionForMedia
|
||||
case animateAvatars
|
||||
case animateHeaders
|
||||
|
|
|
@ -69,6 +69,10 @@ struct PreferencesView: View {
|
|||
Text(option.localizedStringKey).tag(option)
|
||||
}
|
||||
}
|
||||
Toggle("preferences.require-double-tap-to-reblog",
|
||||
isOn: $identityContext.appPreferences.requireDoubleTapToReblog)
|
||||
Toggle("preferences.require-double-tap-to-favorite",
|
||||
isOn: $identityContext.appPreferences.requireDoubleTapToFavorite)
|
||||
if accessibilityReduceMotion {
|
||||
Toggle("preferences.media.use-system-reduce-motion",
|
||||
isOn: $identityContext.appPreferences.useSystemReduceMotionForMedia)
|
||||
|
|
|
@ -245,13 +245,29 @@ private extension StatusView {
|
|||
for: .touchUpInside)
|
||||
|
||||
reblogButton.addAction(
|
||||
UIAction { [weak self] _ in self?.statusConfiguration.viewModel.toggleReblogged() },
|
||||
UIAction { [weak self] _ in
|
||||
guard let self = self,
|
||||
!self.statusConfiguration.viewModel.identityContext.appPreferences.requireDoubleTapToReblog
|
||||
else { return }
|
||||
|
||||
self.reblog()
|
||||
},
|
||||
for: .touchUpInside)
|
||||
|
||||
reblogButton.addTarget(self, action: #selector(reblogButtonDoubleTap(sender:event:)), for: .touchDownRepeat)
|
||||
|
||||
favoriteButton.addAction(
|
||||
UIAction { [weak self] _ in self?.statusConfiguration.viewModel.toggleFavorited() },
|
||||
UIAction { [weak self] _ in
|
||||
guard let self = self,
|
||||
!self.statusConfiguration.viewModel.identityContext.appPreferences.requireDoubleTapToFavorite
|
||||
else { return }
|
||||
|
||||
self.favorite()
|
||||
},
|
||||
for: .touchUpInside)
|
||||
|
||||
favoriteButton.addTarget(self, action: #selector(favoriteButtonDoubleTap(sender:event:)), for: .touchDownRepeat)
|
||||
|
||||
shareButton.addAction(
|
||||
UIAction { [weak self] _ in self?.statusConfiguration.viewModel.shareStatus() },
|
||||
for: .touchUpInside)
|
||||
|
@ -534,6 +550,38 @@ private extension StatusView {
|
|||
menuButton.setImage(UIImage(systemName: "ellipsis",
|
||||
withConfiguration: UIImage.SymbolConfiguration(scale: scale)), for: .normal)
|
||||
}
|
||||
|
||||
@objc func reblogButtonDoubleTap(sender: UIButton, event: UIEvent) {
|
||||
guard
|
||||
statusConfiguration.viewModel.identityContext.appPreferences.requireDoubleTapToReblog,
|
||||
event.allTouches?.first?.tapCount == 2 else {
|
||||
return
|
||||
}
|
||||
|
||||
reblog()
|
||||
}
|
||||
|
||||
@objc func favoriteButtonDoubleTap(sender: UIButton, event: UIEvent) {
|
||||
guard
|
||||
statusConfiguration.viewModel.identityContext.appPreferences.requireDoubleTapToFavorite,
|
||||
event.allTouches?.first?.tapCount == 2 else {
|
||||
return
|
||||
}
|
||||
|
||||
favorite()
|
||||
}
|
||||
|
||||
func reblog() {
|
||||
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
||||
|
||||
statusConfiguration.viewModel.toggleReblogged()
|
||||
}
|
||||
|
||||
func favorite() {
|
||||
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
||||
|
||||
statusConfiguration.viewModel.toggleFavorited()
|
||||
}
|
||||
}
|
||||
|
||||
private extension UIButton {
|
||||
|
|
Loading…
Reference in a new issue