diff --git a/ios/src_library/React Native/RCTContextMenu/RCTContextMenuView.swift b/ios/src_library/React Native/RCTContextMenu/RCTContextMenuView.swift index 3bbb404..a14d27e 100644 --- a/ios/src_library/React Native/RCTContextMenu/RCTContextMenuView.swift +++ b/ios/src_library/React Native/RCTContextMenu/RCTContextMenuView.swift @@ -8,12 +8,13 @@ import Foundation import UIKit + @available(iOS 13, *) class RCTContextMenuView: UIView { @objc var onPressMenuItem: RCTDirectEventBlock?; - private var _menuConfig: RCTMenuItem?; + private var _menuConfig: RCTMenuItem?; @objc var menuConfig: NSDictionary? { didSet { guard @@ -60,7 +61,7 @@ extension RCTContextMenuView: UIContextMenuInteractionDelegate { return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { suggestedActions in return menuConfig.createMenu({ (key, action) in self.onPressMenuItem?(["key": key]); - }) + }); }); }; }; diff --git a/ios/src_library/React Native/RCTContextMenu/RCTMenuActionItem.swift b/ios/src_library/React Native/RCTContextMenu/RCTMenuActionItem.swift index e6e9a00..3eea493 100644 --- a/ios/src_library/React Native/RCTContextMenu/RCTMenuActionItem.swift +++ b/ios/src_library/React Native/RCTContextMenu/RCTMenuActionItem.swift @@ -9,7 +9,8 @@ import Foundation -struct RCTMenuActionItem: Hashable, Encodable, RCTMenuElement { +@available(iOS 13, *) +class RCTMenuActionItem: RCTMenuElement { var actionKey : String; var actionTitle: String; @@ -20,14 +21,10 @@ struct RCTMenuActionItem: Hashable, Encodable, RCTMenuElement { var menuState : String?; var menuAttributes: [String]?; -}; - // ------------------------------ // MARK: RCTMenuActionItem - Init // ------------------------------ -@available(iOS 13, *) -extension RCTMenuActionItem { init?(dictionary: NSDictionary){ guard let actionKey = dictionary["actionKey" ] as? NSString, @@ -67,7 +64,7 @@ extension RCTMenuActionItem { #endif }; - init?(dictionary: NSDictionary?){ + convenience init?(dictionary: NSDictionary?){ guard let dictionary = dictionary else { return nil }; self.init(dictionary: dictionary); }; diff --git a/ios/src_library/React Native/RCTContextMenu/RCTMenuElement.swift b/ios/src_library/React Native/RCTContextMenu/RCTMenuElement.swift new file mode 100644 index 0000000..958e695 --- /dev/null +++ b/ios/src_library/React Native/RCTContextMenu/RCTMenuElement.swift @@ -0,0 +1,20 @@ +// +// RCTMenuProtocols.swift +// IosContextMenuExample +// +// Created by Dominic Go on 10/24/20. +// Copyright © 2020 Facebook. All rights reserved. +// + +import Foundation + + +class RCTMenuElement: Hashable, Encodable { + static func == (lhs: RCTMenuElement, rhs: RCTMenuElement) -> Bool { + return ObjectIdentifier(lhs) == ObjectIdentifier(rhs); + }; + + public func hash(into hasher: inout Hasher) { + hasher.combine(ObjectIdentifier(self).hashValue) + }; +}; diff --git a/ios/src_library/React Native/RCTContextMenu/RCTMenuItem.swift b/ios/src_library/React Native/RCTContextMenu/RCTMenuItem.swift index 5043f5e..0c0c600 100644 --- a/ios/src_library/React Native/RCTContextMenu/RCTMenuItem.swift +++ b/ios/src_library/React Native/RCTContextMenu/RCTMenuItem.swift @@ -9,9 +9,8 @@ import UIKit; -struct RCTMenuElementItem: RCTMenuElement {}; - -struct RCTMenuItem: Hashable, Encodable where T: RCTMenuElement { +@available(iOS 13.0, *) +class RCTMenuItem: RCTMenuElement { var menuTitle: String; @@ -19,18 +18,13 @@ struct RCTMenuItem: Hashable, Encodable where T: RCTMenuElement { var imageType : ImageType = .NONE; var imageValue : String?; - var menuItems: Array?; + var menuItems: [RCTMenuElement]?; -}; - // ------------------------ // MARK: RCTMenuItem - Init // ------------------------ -@available(iOS 13, *) -extension RCTMenuItem { init?(dictionary: NSDictionary){ - guard let menuTitle = dictionary["menuTitle"] as? NSString else { #if DEBUG print("RCTMenuItem, init failed - menuTitle: nil"); @@ -64,13 +58,13 @@ extension RCTMenuItem { #if DEBUG print("RCTMenuItem, init - compactMap: Creating RCTMenuItem..."); #endif - return menuItem as? T; + return menuItem; } else if let menuAction = RCTMenuActionItem(dictionary: $0 as? NSDictionary) { #if DEBUG print("RCTMenuItem, init - compactMap: Creating RCTMenuActionItem..."); #endif - return menuAction as? T; + return menuAction; } else { #if DEBUG @@ -88,7 +82,7 @@ extension RCTMenuItem { #endif }; - init?(dictionary: NSDictionary?){ + convenience init?(dictionary: NSDictionary?){ guard let dictionary = dictionary else { return nil }; self.init(dictionary: dictionary); }; @@ -166,3 +160,5 @@ extension RCTMenuItem { }; + + diff --git a/ios/src_library/React Native/RCTContextMenu/RCTMenuProtocols.swift b/ios/src_library/React Native/RCTContextMenu/RCTMenuProtocols.swift deleted file mode 100644 index 0dc6300..0000000 --- a/ios/src_library/React Native/RCTContextMenu/RCTMenuProtocols.swift +++ /dev/null @@ -1,12 +0,0 @@ -// -// RCTMenuProtocols.swift -// IosContextMenuExample -// -// Created by Dominic Go on 10/24/20. -// Copyright © 2020 Facebook. All rights reserved. -// - -import Foundation - - -protocol RCTMenuElement: Hashable, Encodable {};