@@ -214,7 +214,7 @@ index 352d8fa656aac2e39160104df2394ebe6719bac5..040701e5d7ee498a896f03ecc79fc992 |
214 | 214 | private var _themeVariant: String? |
215 | 215 | @objc public var themeVariant: NSString? { |
216 | 216 | diff --git a/ios/Shared/MenuViewImplementation.swift b/ios/Shared/MenuViewImplementation.swift |
217 | | -index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224ed38a69b7 100644 |
| 217 | +index 5c4e0da4292b15d3a27b5ea1555f11452a470815..bbfd7e3f0fcdc3e522efc69307d59c8555e6f7ce 100644 |
218 | 218 | --- a/ios/Shared/MenuViewImplementation.swift |
219 | 219 | +++ b/ios/Shared/MenuViewImplementation.swift |
220 | 220 | @@ -42,6 +42,14 @@ public class MenuViewImplementation: UIButton { |
@@ -225,7 +225,7 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e |
225 | 225 | + /// context-menu timing. |
226 | 226 | + @objc public var longPressDuration: Int = 0 { |
227 | 227 | + didSet { |
228 | | -+ self.updateQuickLongPress() |
| 228 | ++ self.updateLongPressDuration() |
229 | 229 | + } |
230 | 230 | + } |
231 | 231 | + |
@@ -281,7 +281,7 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e |
281 | 281 | func setup () { |
282 | 282 | let menu = UIMenu(title: _title, |
283 | 283 | identifier: nil, |
284 | | -@@ -86,8 +123,141 @@ public class MenuViewImplementation: UIButton { |
| 284 | +@@ -86,10 +123,126 @@ public class MenuViewImplementation: UIButton { |
285 | 285 | } |
286 | 286 | } |
287 | 287 |
|
@@ -307,9 +307,9 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e |
307 | 307 | + // the wrapped content as the zoom preview. |
308 | 308 | + self.isUserInteractionEnabled = !shouldOpenOnLongPress |
309 | 309 | + self.updateLongPressInteraction() |
310 | | -+ self.updateQuickLongPress() |
311 | | -+ } |
312 | | -+ |
| 310 | ++ self.updateLongPressDuration() |
| 311 | + } |
| 312 | + |
313 | 313 | + private func refreshPresentedMenu(_ menu: UIMenu) { |
314 | 314 | + // Tap mode presents through the button's built-in interaction, |
315 | 315 | + // long-press mode through the superview-hosted one; cover both (plus |
@@ -359,44 +359,26 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e |
359 | 359 | + public override func didMoveToSuperview() { |
360 | 360 | + super.didMoveToSuperview() |
361 | 361 | + self.updateLongPressInteraction() |
362 | | -+ self.updateQuickLongPress() |
| 362 | ++ self.updateLongPressDuration() |
363 | 363 | + } |
364 | 364 | + |
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 | ++ } |
384 | 381 | + } |
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)) |
400 | 382 | + } |
401 | 383 | + |
402 | 384 | + private func updateLongPressInteraction() { |
@@ -420,10 +402,13 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e |
420 | 402 | + self.addInteraction(existing) |
421 | 403 | + longPressInteraction = nil |
422 | 404 | + } |
423 | | - } |
424 | | - |
| 405 | ++ } |
| 406 | ++ |
| 407 | ++ |
425 | 408 | 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 { |
427 | 412 | @objc func sendMenuOpen() { |
428 | 413 | // NO-OP (should be overriden by parent) |
429 | 414 | } |
@@ -433,12 +418,35 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..dc710f29c7cccd55b4049c7dce3e224e |
433 | 418 | + } |
434 | 419 | +} |
435 | 420 | + |
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 |
442 | 450 | + } |
443 | 451 | } |
444 | 452 | diff --git a/ios/Shared/RCTMenuItem.swift b/ios/Shared/RCTMenuItem.swift |
|