GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mobile): shorten the native menu hold instead of re-presenting it · pingdotgg/t3code@3a79e1a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • patches
    • @[email protected]
  • pnpm-lock.yaml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎patches/@[email protected]‎

Copy file name to clipboardExpand all lines: patches/@[email protected]
+58-50Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ index 352d8fa656aac2e39160104df2394ebe6719bac5..040701e5d7ee498a896f03ecc79fc992
214214
private var _themeVariant: String?
215215
@objc public var themeVariant: NSString? {
216216
diff --git a/ios/Shared/MenuViewImplementation.swift b/ios/Shared/MenuViewImplementation.swift
217-
index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224ed38a69b7 100644
217+
index 5c4e0da4292b15d3a27b5ea1555f11452a470815..bbfd7e3f0fcdc3e522efc69307d59c8555e6f7ce 100644
218218
--- a/ios/Shared/MenuViewImplementation.swift
219219
+++ b/ios/Shared/MenuViewImplementation.swift
220220
@@ -42,6 +42,14 @@ public class MenuViewImplementation: UIButton {
@@ -225,7 +225,7 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e
225225
+ /// context-menu timing.
226226
+ @objc public var longPressDuration: Int = 0 {
227227
+ didSet {
228-
+ self.updateQuickLongPress()
228+
+ self.updateLongPressDuration()
229229
+ }
230230
+ }
231231
+
@@ -281,7 +281,7 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e
281281
func setup () {
282282
let menu = UIMenu(title: _title,
283283
identifier: nil,
284-
@@ -86,8 +123,141 @@ public class MenuViewImplementation: UIButton {
284+
@@ -86,10 +123,126 @@ public class MenuViewImplementation: UIButton {
285285
}
286286
}
287287

@@ -307,9 +307,9 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e
307307
+ // the wrapped content as the zoom preview.
308308
+ self.isUserInteractionEnabled = !shouldOpenOnLongPress
309309
+ self.updateLongPressInteraction()
310-
+ self.updateQuickLongPress()
311-
+ }
312-
+
310+
+ self.updateLongPressDuration()
311+
}
312+
313313
+ private func refreshPresentedMenu(_ menu: UIMenu) {
314314
+ // Tap mode presents through the button's built-in interaction,
315315
+ // long-press mode through the superview-hosted one; cover both (plus
@@ -359,44 +359,26 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e
359359
+ public override func didMoveToSuperview() {
360360
+ super.didMoveToSuperview()
361361
+ self.updateLongPressInteraction()
362-
+ self.updateQuickLongPress()
362+
+ self.updateLongPressDuration()
363363
+ }
364364
+
365-
+ private var quickLongPress: UILongPressGestureRecognizer?
366-
+ private let quickLongPressDelegate = SimultaneousGestureDelegate()
367-
+
368-
+ private func updateQuickLongPress() {
369-
+ let host = longPressDuration > 0 ? longPressInteraction?.view : nil
370-
+ if let existing = quickLongPress, existing.view !== host {
371-
+ existing.view?.removeGestureRecognizer(existing)
372-
+ quickLongPress = nil
373-
+ }
374-
+ guard let host = host else { return }
375-
+ if quickLongPress == nil {
376-
+ let recognizer = UILongPressGestureRecognizer(
377-
+ target: self, action: #selector(presentMenuAfterQuickLongPress(_:)))
378-
+ // Observe the hold alongside the wrapped React touchables instead
379-
+ // of stealing their touches, so a short tap still lands as a press.
380-
+ recognizer.cancelsTouchesInView = false
381-
+ recognizer.delegate = quickLongPressDelegate
382-
+ host.addGestureRecognizer(recognizer)
383-
+ quickLongPress = recognizer
365+
+ private func updateLongPressDuration() {
366+
+ guard let host = longPressInteraction?.view else { return }
367+
+ let seconds: NSNumber? = longPressDuration > 0 ? NSNumber(value: Double(longPressDuration) / 1000) : nil
368+
+ // UIKit exposes no hold-duration setting, but UIControl's long-press
369+
+ // menu reads it from its click driver: clickDownDuration decides when a
370+
+ // release counts as a menu press, clickTimeoutDuration when a held press
371+
+ // opens the menu. Give this driver a subclass that answers both with our
372+
+ // duration, so the native menu opens sooner without being re-presented
373+
+ // by hand. Unrecognized UIKit internals leave the system timing alone.
374+
+ for recognizer in host.gestureRecognizers ?? [] {
375+
+ guard let driver = recognizer.delegate as? NSObject,
376+
+ let durationClass = LongPressDurationDriver.subclass(of: type(of: driver)) else { continue }
377+
+ objc_setAssociatedObject(driver, &LongPressDurationDriver.key, seconds, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
378+
+ if seconds != nil && type(of: driver) !== durationClass {
379+
+ object_setClass(driver, durationClass)
380+
+ }
384381
+ }
385-
+ quickLongPress?.minimumPressDuration = TimeInterval(longPressDuration) / 1000
386-
+ }
387-
+
388-
+ @objc private func presentMenuAfterQuickLongPress(_ recognizer: UILongPressGestureRecognizer) {
389-
+ guard recognizer.state == .began,
390-
+ let interaction = longPressInteraction,
391-
+ let host = interaction.view else { return }
392-
+ // UIKit has no public way to shorten a context-menu hold. Present
393-
+ // through the interaction's own entry point when it exists; without
394-
+ // it the system long press still opens the menu at its usual timing.
395-
+ let selector = NSSelectorFromString("_presentMenuAtLocation:")
396-
+ guard interaction.responds(to: selector) else { return }
397-
+ typealias PresentMenu = @convention(c) (AnyObject, Selector, CGPoint) -> Void
398-
+ let present = unsafeBitCast(interaction.method(for: selector), to: PresentMenu.self)
399-
+ present(interaction, selector, recognizer.location(in: host))
400382
+ }
401383
+
402384
+ private func updateLongPressInteraction() {
@@ -420,10 +402,13 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e
420402
+ self.addInteraction(existing)
421403
+ longPressInteraction = nil
422404
+ }
423-
}
424-
405+
+ }
406+
+
407+
+
425408
public override func reactSetFrame(_ frame: CGRect) {
426-
@@ -124,4 +294,17 @@ public class MenuViewImplementation: UIButton {
409+
super.reactSetFrame(frame);
410+
}
411+
@@ -124,4 +277,40 @@ public class MenuViewImplementation: UIButton {
427412
@objc func sendMenuOpen() {
428413
// NO-OP (should be overriden by parent)
429414
}
@@ -433,12 +418,35 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e
433418
+ }
434419
+}
435420
+
436-
+private final class SimultaneousGestureDelegate: NSObject, UIGestureRecognizerDelegate {
437-
+ func gestureRecognizer(
438-
+ _ gestureRecognizer: UIGestureRecognizer,
439-
+ shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer
440-
+ ) -> Bool {
441-
+ true
421+
+private enum LongPressDurationDriver {
422+
+ static var key: UInt8 = 0
423+
+ private static let prefix = "T3LongPressDuration_"
424+
+ private static let selectors = ["clickDownDuration", "clickTimeoutDuration"].map(NSSelectorFromString)
425+
+
426+
+ /// A subclass of UIKit's long-press click driver whose hold durations
427+
+ /// return the associated override, falling back to UIKit's own values.
428+
+ static func subclass(of base: AnyClass) -> AnyClass? {
429+
+ let baseName = NSStringFromClass(base)
430+
+ if baseName.hasPrefix(prefix) { return base }
431+
+ guard baseName.hasPrefix("_UI"), baseName.hasSuffix("LongPressClickInteractionDriver"),
432+
+ selectors.allSatisfy({ class_getInstanceMethod(base, $0) != nil }) else { return nil }
433+
+ let name = prefix + baseName
434+
+ if let existing = NSClassFromString(name) { return existing }
435+
+ guard let subclass = objc_allocateClassPair(base, name, 0) else { return nil }
436+
+ typealias Getter = @convention(c) (AnyObject, Selector) -> Double
437+
+ for selector in selectors {
438+
+ guard let inherited = class_getMethodImplementation(base, selector) else { continue }
439+
+ let original = unsafeBitCast(inherited, to: Getter.self)
440+
+ let getter: @convention(block) (AnyObject) -> Double = { driver in
441+
+ if let seconds = objc_getAssociatedObject(driver, &key) as? NSNumber {
442+
+ return seconds.doubleValue
443+
+ }
444+
+ return original(driver, selector)
445+
+ }
446+
+ class_addMethod(subclass, selector, imp_implementationWithBlock(getter), "d@:")
447+
+ }
448+
+ objc_registerClassPair(subclass)
449+
+ return subclass
442450
+ }
443451
}
444452
diff --git a/ios/Shared/RCTMenuItem.swift b/ios/Shared/RCTMenuItem.swift
Collapse file

‎pnpm-lock.yaml‎

Copy file name to clipboardExpand all lines: pnpm-lock.yaml
+3-3Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.