@react-native-menu/menu 0.9.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +14 -2
  2. package/android/.project +11 -0
  3. package/android/build.gradle +69 -77
  4. package/android/gradle.properties +5 -4
  5. package/android/src/main/AndroidManifest.xml +0 -1
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/com/reactnativemenu/MenuPackage.kt +1 -1
  8. package/android/src/main/java/com/reactnativemenu/MenuViewManager.kt +3 -3
  9. package/android/src/newarch/MenuViewManagerSpec.kt +21 -0
  10. package/android/src/oldarch/MenuViewManagerSpec.kt +9 -0
  11. package/ios/Menu-Bridging-Header.h +0 -2
  12. package/ios/MenuViewManager.mm +64 -0
  13. package/ios/NewArch/FabricActionSheetView.swift +11 -0
  14. package/ios/NewArch/FabricMenuViewImplementation.swift +20 -0
  15. package/ios/NewArch/FabricViewImplementationProtocol.swift +6 -0
  16. package/ios/NewArch/MenuView.h +19 -0
  17. package/ios/NewArch/MenuView.mm +145 -0
  18. package/ios/OldArch/LegacyActionSheetView.swift +11 -0
  19. package/ios/OldArch/LegacyMenuViewImplementation.swift +13 -0
  20. package/ios/{ActionSheetView.swift → Shared/ActionSheetView.swift} +6 -8
  21. package/ios/{MenuView.swift → Shared/MenuViewImplementation.swift} +9 -11
  22. package/ios/{RCTMenuItem.swift → Shared/RCTMenuItem.swift} +9 -1
  23. package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js +18 -0
  24. package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -0
  25. package/lib/commonjs/UIMenuView.android.js +1 -4
  26. package/lib/commonjs/UIMenuView.android.js.map +1 -1
  27. package/lib/commonjs/UIMenuView.ios.js +3 -6
  28. package/lib/commonjs/UIMenuView.ios.js.map +1 -1
  29. package/lib/commonjs/UIMenuView.js +3 -10
  30. package/lib/commonjs/UIMenuView.js.map +1 -1
  31. package/lib/commonjs/index.js +12 -14
  32. package/lib/commonjs/index.js.map +1 -1
  33. package/lib/commonjs/types.js.map +1 -1
  34. package/lib/commonjs/utils.js +31 -0
  35. package/lib/commonjs/utils.js.map +1 -0
  36. package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js +12 -0
  37. package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -0
  38. package/lib/module/UIMenuView.android.js.map +1 -1
  39. package/lib/module/UIMenuView.ios.js +2 -3
  40. package/lib/module/UIMenuView.ios.js.map +1 -1
  41. package/lib/module/UIMenuView.js +0 -2
  42. package/lib/module/UIMenuView.js.map +1 -1
  43. package/lib/module/index.js +10 -10
  44. package/lib/module/index.js.map +1 -1
  45. package/lib/module/types.js.map +1 -1
  46. package/lib/module/utils.js +25 -0
  47. package/lib/module/utils.js.map +1 -0
  48. package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts +44 -0
  49. package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts.map +1 -0
  50. package/lib/typescript/src/UIMenuView.android.d.ts +1 -0
  51. package/lib/typescript/src/UIMenuView.android.d.ts.map +1 -0
  52. package/lib/typescript/src/UIMenuView.d.ts +1 -0
  53. package/lib/typescript/src/UIMenuView.d.ts.map +1 -0
  54. package/lib/typescript/src/UIMenuView.ios.d.ts +3 -4
  55. package/lib/typescript/src/UIMenuView.ios.d.ts.map +1 -0
  56. package/lib/typescript/src/index.d.ts +1 -0
  57. package/lib/typescript/src/index.d.ts.map +1 -0
  58. package/lib/typescript/src/types.d.ts +2 -0
  59. package/lib/typescript/src/types.d.ts.map +1 -0
  60. package/lib/typescript/src/utils.d.ts +2 -0
  61. package/lib/typescript/src/utils.d.ts.map +1 -0
  62. package/package.json +38 -20
  63. package/react-native-menu.podspec +26 -4
  64. package/src/NativeModuleSpecs/UIMenuNativeComponent.ts +55 -0
  65. package/src/UIMenuView.ios.tsx +2 -7
  66. package/src/index.tsx +8 -2
  67. package/src/types.ts +2 -0
  68. package/src/utils.ts +24 -0
  69. package/ios/Menu.xcodeproj/project.pbxproj +0 -297
  70. package/ios/RCTUIMenuManager.m +0 -27
  71. package/ios/RCTUIMenuManager.swift +0 -19
  72. /package/ios/{RCTAlertAction.swift → Shared/RCTAlertAction.swift} +0 -0
package/README.md CHANGED
@@ -37,6 +37,18 @@ The package is [automatically linked](https://github.com/react-native-community/
37
37
  npx pod-install
38
38
  ```
39
39
 
40
+ ## Fabric
41
+
42
+ If you plan on using fabric with this project, you may want to add the following lines on your projects' Podfile:
43
+
44
+ ```ruby
45
+ + # @react-native-menu/menu (fabric+swift requirements)
46
+ + pod 'React-Fabric', :modular_headers => true, :path => '../node_modules/react-native/ReactCommon'
47
+ + pod 'React-graphics', :modular_headers => true, :path => '../node_modules/react-native/ReactCommon/react/renderer/graphics'
48
+ + pod 'React-utils', :modular_headers => true, :path => '../node_modules/react-native/ReactCommon/react/utils'
49
+ + pod 'React-debug', :modular_headers => true, :path => '../node_modules/react-native/ReactCommon/react/debug'
50
+ ```
51
+
40
52
  ## Usage
41
53
 
42
54
  ```jsx
@@ -111,7 +123,7 @@ const App = () => {
111
123
  }),
112
124
  },
113
125
  ]}
114
- shouldOpenOnLongPress={true}
126
+ shouldOpenOnLongPress={false}
115
127
  >
116
128
  <View style={styles.button}>
117
129
  <Text style={styles.buttonText}>Test</Text>
@@ -160,7 +172,7 @@ Actions to be displayed in the menu.
160
172
 
161
173
  ### `themeVariant` (iOS only)
162
174
 
163
- String to override theme of menu
175
+ String to override theme of the menu. If you want to control theme universally across your app, [see this package](https://github.com/vonovak/react-native-theme-control).
164
176
 
165
177
  | Type | Required |
166
178
  | ------------ | -------- |
package/android/.project CHANGED
@@ -14,4 +14,15 @@
14
14
  <natures>
15
15
  <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16
16
  </natures>
17
+ <filteredResources>
18
+ <filter>
19
+ <id>1708364511770</id>
20
+ <name></name>
21
+ <type>30</type>
22
+ <matcher>
23
+ <id>org.eclipse.core.resources.regexFilterMatcher</id>
24
+ <arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25
+ </matcher>
26
+ </filter>
27
+ </filteredResources>
17
28
  </projectDescription>
@@ -8,32 +8,63 @@ buildscript {
8
8
  }
9
9
 
10
10
  dependencies {
11
- classpath 'com.android.tools.build:gradle:3.2.1'
11
+ classpath "com.android.tools.build:gradle:7.2.1"
12
12
  // noinspection DifferentKotlinGradleVersion
13
13
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
14
  }
15
15
  }
16
16
 
17
- apply plugin: 'com.android.library'
18
- apply plugin: 'kotlin-android'
17
+ def isNewArchitectureEnabled() {
18
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
+ }
20
+
21
+ apply plugin: "com.android.library"
22
+ apply plugin: "kotlin-android"
23
+
24
+ if (isNewArchitectureEnabled()) {
25
+ apply plugin: "com.facebook.react"
26
+ }
19
27
 
20
28
  def getExtOrDefault(name) {
21
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Menu_' + name]
29
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Menu_" + name]
22
30
  }
23
31
 
24
32
  def getExtOrIntegerDefault(name) {
25
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['Menu_' + name]).toInteger()
33
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Menu_" + name]).toInteger()
34
+ }
35
+
36
+ def supportsNamespace() {
37
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
38
+ def major = parsed[0].toInteger()
39
+ def minor = parsed[1].toInteger()
40
+
41
+ // Namespace support was added in 7.3.0
42
+ return (major == 7 && minor >= 3) || major >= 8
26
43
  }
27
44
 
28
45
  android {
29
- compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
30
- buildToolsVersion getExtOrDefault('buildToolsVersion')
46
+ if (supportsNamespace()) {
47
+ namespace "com.reactnativemenu"
48
+
49
+ sourceSets {
50
+ main {
51
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
52
+ }
53
+ }
54
+ }
55
+
56
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
57
+
31
58
  defaultConfig {
32
59
  minSdkVersion 21
33
- targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
60
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
61
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
34
62
  versionCode 1
35
63
  versionName "1.0"
64
+ }
36
65
 
66
+ buildFeatures {
67
+ buildConfig true
37
68
  }
38
69
 
39
70
  buildTypes {
@@ -41,89 +72,50 @@ android {
41
72
  minifyEnabled false
42
73
  }
43
74
  }
75
+
44
76
  lintOptions {
45
- disable 'GradleCompatible'
77
+ disable "GradleCompatible"
46
78
  }
79
+
47
80
  compileOptions {
48
81
  sourceCompatibility JavaVersion.VERSION_1_8
49
82
  targetCompatibility JavaVersion.VERSION_1_8
50
83
  }
84
+
85
+ sourceSets {
86
+ main {
87
+ if (isNewArchitectureEnabled()) {
88
+ java.srcDirs += [
89
+ "src/newarch",
90
+ // This is needed to build Kotlin project with NewArch enabled
91
+ "${project.buildDir}/generated/source/codegen/java"
92
+ ]
93
+ } else {
94
+ java.srcDirs += ["src/oldarch"]
95
+ }
96
+ }
97
+ }
51
98
  }
52
99
 
53
100
  repositories {
54
101
  mavenCentral()
55
102
  google()
56
-
57
- def found = false
58
- def defaultDir = null
59
- def androidSourcesName = 'React Native sources'
60
-
61
- if (rootProject.ext.has('reactNativeAndroidRoot')) {
62
- defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
63
- } else {
64
- defaultDir = new File(
65
- projectDir,
66
- '/../../../node_modules/react-native/android'
67
- )
68
- }
69
-
70
- if (defaultDir.exists()) {
71
- maven {
72
- url defaultDir.toString()
73
- name androidSourcesName
74
- }
75
-
76
- logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
77
- found = true
78
- } else {
79
- def parentDir = rootProject.projectDir
80
-
81
- 1.upto(5, {
82
- if (found) return true
83
- parentDir = parentDir.parentFile
84
-
85
- def androidSourcesDir = new File(
86
- parentDir,
87
- 'node_modules/react-native'
88
- )
89
-
90
- def androidPrebuiltBinaryDir = new File(
91
- parentDir,
92
- 'node_modules/react-native/android'
93
- )
94
-
95
- if (androidPrebuiltBinaryDir.exists()) {
96
- maven {
97
- url androidPrebuiltBinaryDir.toString()
98
- name androidSourcesName
99
- }
100
-
101
- logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
102
- found = true
103
- } else if (androidSourcesDir.exists()) {
104
- maven {
105
- url androidSourcesDir.toString()
106
- name androidSourcesName
107
- }
108
-
109
- logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
110
- found = true
111
- }
112
- })
113
- }
114
-
115
- if (!found) {
116
- throw new GradleException(
117
- "${project.name}: unable to locate React Native android sources. " +
118
- "Ensure you have you installed React Native as a dependency in your project and try again."
119
- )
120
- }
121
103
  }
122
104
 
123
- def kotlin_version = getExtOrDefault('kotlinVersion')
105
+ def kotlin_version = getExtOrDefault("kotlinVersion")
124
106
 
125
107
  dependencies {
126
- // noinspection GradleDynamicVersion
127
- api 'com.facebook.react:react-native:+'
108
+ // For < 0.71, this will be from the local maven repo
109
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
110
+ //noinspection GradleDynamicVersion
111
+ implementation "com.facebook.react:react-native:+"
128
112
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
129
113
  }
114
+
115
+ if (isNewArchitectureEnabled()) {
116
+ react {
117
+ jsRootDir = file("../src/")
118
+ libraryName = "MenuView"
119
+ codegenJavaPackageName = "com.reactnativemenu"
120
+ }
121
+ }
@@ -1,4 +1,5 @@
1
- Menu_kotlinVersion=1.6.10
2
- Menu_compileSdkVersion=30
3
- Menu_buildToolsVersion=30.0.3
4
- Menu_targetSdkVersion=30
1
+ Menu_kotlinVersion=1.7.0
2
+ Menu_minSdkVersion=21
3
+ Menu_targetSdkVersion=31
4
+ Menu_compileSdkVersion=31
5
+ Menu_ndkversion=21.4.7075529
@@ -1,4 +1,3 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
2
  package="com.reactnativemenu">
3
-
4
3
  </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -17,4 +17,4 @@ class MenuPackage : ReactPackage {
17
17
  override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
18
18
  return mutableListOf(MenuViewManager())
19
19
  }
20
- }
20
+ }
@@ -110,13 +110,13 @@ class MenuViewManager: ReactClippingViewManager<MenuView>() {
110
110
  @ReactProp(name = "hitSlop")
111
111
  fun setHitSlop(view: ReactViewGroup, @Nullable hitSlop: ReadableMap?) {
112
112
  if (hitSlop == null) {
113
- view.hitSlopRect = null
113
+ view.setHitSlopRect(null)
114
114
  } else {
115
- view.hitSlopRect = Rect(
115
+ view.setHitSlopRect(Rect(
116
116
  if (hitSlop.hasKey("left")) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")).toInt() else 0,
117
117
  if (hitSlop.hasKey("top")) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")).toInt() else 0,
118
118
  if (hitSlop.hasKey("right")) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")).toInt() else 0,
119
- if (hitSlop.hasKey("bottom")) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom")).toInt() else 0)
119
+ if (hitSlop.hasKey("bottom")) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom")).toInt() else 0))
120
120
  }
121
121
  }
122
122
 
@@ -0,0 +1,21 @@
1
+ package com.reactnativemenu
2
+
3
+ import android.view.View
4
+
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.SimpleViewManager
7
+ import com.facebook.react.uimanager.ViewManagerDelegate
8
+ import com.facebook.react.viewmanagers.MenuViewManagerDelegate
9
+ import com.facebook.react.viewmanagers.MenuViewManagerInterface
10
+
11
+ abstract class MenuViewManagerSpec<T : View> : SimpleViewManager<T>(), MenuViewManagerInterface<T> {
12
+ private val mDelegate: ViewManagerDelegate<T>
13
+
14
+ init {
15
+ mDelegate = MenuViewManagerDelegate(this)
16
+ }
17
+
18
+ override fun getDelegate(): ViewManagerDelegate<T>? {
19
+ return mDelegate
20
+ }
21
+ }
@@ -0,0 +1,9 @@
1
+ package com.reactnativemenu
2
+
3
+ import android.view.View
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.uimanager.SimpleViewManager
6
+
7
+ abstract class MenuViewManagerSpec<T : View> : SimpleViewManager<T>() {
8
+ abstract fun setColor(view: T?, value: String?)
9
+ }
@@ -1,5 +1,3 @@
1
1
  #import <React/RCTBridgeModule.h>
2
2
  #import <React/RCTViewManager.h>
3
3
  #import <React/RCTView.h>
4
-
5
-
@@ -0,0 +1,64 @@
1
+ #import <React/RCTViewManager.h>
2
+ #import <React/RCTUIManager.h>
3
+ #import "RCTBridge.h"
4
+
5
+ #ifdef RCT_NEW_ARCH_ENABLED
6
+ // NEW ARCH
7
+ #import "MenuView.h"
8
+ #else
9
+ // OLD ARCH
10
+ #import <react_native_menu-Swift.h>
11
+ #endif
12
+
13
+ @interface MenuViewManager : RCTViewManager
14
+ @end
15
+
16
+ @implementation MenuViewManager
17
+
18
+ RCT_EXPORT_MODULE(MenuView)
19
+
20
+ - (UIView *)view
21
+ {
22
+ #ifdef RCT_NEW_ARCH_ENABLED
23
+ // NEW ARCH
24
+ return [[MenuView alloc] init];
25
+ #else
26
+ // OLD ARCH
27
+ if (@available(iOS 14.0, *)) {
28
+ return [[LegacyMenuViewImplementation alloc] init];
29
+ } else {
30
+ return [[LegacyActionSheetView alloc] init];
31
+ }
32
+ #endif /* RCT_NEW_ARCH_ENABLED */
33
+ }
34
+
35
+ /**
36
+ * title: Short description to be displayed above the menu.
37
+ */
38
+ RCT_EXPORT_VIEW_PROPERTY(title, NSString);
39
+ /**
40
+ * actions: Array of actions that are included in the menu
41
+ */
42
+ RCT_EXPORT_VIEW_PROPERTY(actions, NSArray);
43
+ /**
44
+ * actionsHash: String hash that changes any time the actions change (so that we don't have to deeply compare values)
45
+ */
46
+ #ifdef RCT_NEW_ARCH_ENABLED
47
+ // NEW ARCH
48
+ RCT_EXPORT_VIEW_PROPERTY(actionsHash, NSString);
49
+ #endif
50
+
51
+ /**
52
+ * onPressAction: callback to be called once user selects an action
53
+ */
54
+ RCT_EXPORT_VIEW_PROPERTY(onPressAction, RCTDirectEventBlock);
55
+ /**
56
+ * shouldOpenOnLongPress: determines whether menu should be opened after long press or normal press
57
+ */
58
+ RCT_EXPORT_VIEW_PROPERTY(shouldOpenOnLongPress, BOOL)
59
+ /**
60
+ * themeVariant: determines whether menu should use dark theme, light theme or system theme
61
+ */
62
+ RCT_EXPORT_VIEW_PROPERTY(themeVariant, NSString)
63
+
64
+ @end
@@ -0,0 +1,11 @@
1
+
2
+ @objc(FabricActionSheetView)
3
+ public class FabricActionSheetView: ActionSheetView, FabricViewImplementationProtocol {
4
+ public var onPressAction: ((String) -> Void)?
5
+
6
+ @objc override func sendButtonAction(_ action: String) {
7
+ if let onPress = onPressAction {
8
+ onPress(action)
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,20 @@
1
+ //
2
+ // MenuViewImplementation.swift
3
+ // react-native-menu
4
+ //
5
+ // Created by Jesse Katsumata on 11/3/20.
6
+ //
7
+
8
+ import UIKit
9
+ @available(iOS 14.0, *)
10
+ @objc(FabricMenuViewImplementation)
11
+ public class FabricMenuViewImplementation: MenuViewImplementation, FabricViewImplementationProtocol {
12
+ public var onPressAction: ((String) -> Void)?
13
+
14
+ @objc override func sendButtonAction(_ action: UIAction) {
15
+ if let onPress = onPressAction {
16
+ onPress(action.identifier.rawValue)
17
+ }
18
+ }
19
+
20
+ }
@@ -0,0 +1,6 @@
1
+ import Foundation
2
+ @objc public protocol FabricViewImplementationProtocol {
3
+ var actions: [NSDictionary]? { get set }
4
+ var title: NSString? { get set }
5
+ var onPressAction: ((String) -> Void)? { get set }
6
+ }
@@ -0,0 +1,19 @@
1
+ // This guard prevent this file to be compiled in the old architecture.
2
+
3
+ #ifdef RCT_NEW_ARCH_ENABLED
4
+ #import <React/RCTViewComponentView.h>
5
+ #import <UIKit/UIKit.h>
6
+
7
+ #ifndef MenuViewNativeComponent_h
8
+ #define MenuViewNativeComponent_h
9
+
10
+ NS_ASSUME_NONNULL_BEGIN
11
+
12
+ @protocol FabricViewImplementationProtocol;
13
+ @interface MenuView : RCTViewComponentView
14
+ @end
15
+
16
+ NS_ASSUME_NONNULL_END
17
+
18
+ #endif /* MenuViewNativeComponent_h */
19
+ #endif /* RCT_NEW_ARCH_ENABLED */
@@ -0,0 +1,145 @@
1
+ #ifdef RCT_NEW_ARCH_ENABLED
2
+ #import <react_native_menu-Swift.h>
3
+ #import "MenuView.h"
4
+
5
+ #import <react/renderer/components/RNMenuViewSpec/ComponentDescriptors.h>
6
+ #import <react/renderer/components/RNMenuViewSpec/EventEmitters.h>
7
+ #import <react/renderer/components/RNMenuViewSpec/Props.h>
8
+ #import <react/renderer/components/RNMenuViewSpec/RCTComponentViewHelpers.h>
9
+ #import "RCTFabricComponentsPlugins.h"
10
+
11
+ using namespace facebook::react;
12
+
13
+ @interface MenuView () <RCTMenuViewViewProtocol>
14
+
15
+ @end
16
+
17
+ @implementation MenuView {
18
+ UIView <FabricViewImplementationProtocol> * _view;
19
+ }
20
+
21
+ + (ComponentDescriptorProvider)componentDescriptorProvider
22
+ {
23
+ return concreteComponentDescriptorProvider<MenuViewComponentDescriptor>();
24
+ }
25
+
26
+ - (instancetype)initWithFrame:(CGRect)frame
27
+ {
28
+ if (self = [super initWithFrame:frame]) {
29
+ static const auto defaultProps = std::make_shared<const MenuViewProps>();
30
+ _props = defaultProps;
31
+
32
+ if (@available(iOS 14.0, *)) {
33
+ _view = [[FabricMenuViewImplementation alloc] init];
34
+ } else {
35
+ _view = [[FabricActionSheetView alloc] init];
36
+ }
37
+ _view.onPressAction = ^(NSString *eventString) {
38
+ [self onPressAction:eventString];
39
+ };
40
+ self.contentView = _view;
41
+ }
42
+
43
+ return self;
44
+ }
45
+
46
+ - (std::shared_ptr<const MenuViewEventEmitter>)getEventEmitter
47
+ {
48
+ if (!self->_eventEmitter) {
49
+ return nullptr;
50
+ }
51
+
52
+ assert(std::dynamic_pointer_cast<MenuViewEventEmitter const>(self->_eventEmitter));
53
+ return std::static_pointer_cast<MenuViewEventEmitter const>(self->_eventEmitter);
54
+ }
55
+
56
+ - (void)onPressAction:(NSString * _Nonnull)eventString {
57
+ // If screen is already unmounted then there will be no event emitter
58
+ const auto eventEmitter = [self getEventEmitter];
59
+ if (eventEmitter != nullptr) {
60
+
61
+ eventEmitter->onPressAction(MenuViewEventEmitter::OnPressAction{
62
+ .event = [eventString UTF8String]
63
+ });
64
+ }
65
+ }
66
+
67
+ /**
68
+ Responsible for iterating through the C++ vector<struct> and convert each struct element to NSDictionary, then return it all in an NSArray
69
+ */
70
+ - (NSMutableArray<NSDictionary *> *) convertActionsToObjC: (std::vector<MenuViewActionsStruct>) actions {
71
+ if (actions.size() == 0) {
72
+ return @[];
73
+ }
74
+ NSMutableArray<NSDictionary *> *actionsArray = [NSMutableArray arrayWithCapacity:actions.size()];
75
+ for (const MenuViewActionsStruct &action : actions) {
76
+ // first convert the subactions if they exist
77
+ NSMutableArray<NSDictionary *> *subactionsArray = [NSMutableArray arrayWithCapacity:actions.size()];
78
+ if (action.subactions.size() > 0) {
79
+ for (const MenuViewActionsSubactionsStruct &subaction : action.subactions) {
80
+ NSDictionary *subactionDict = @{
81
+ @"id": [NSString stringWithUTF8String:subaction.id.c_str()],
82
+ @"title": [NSString stringWithUTF8String:subaction.title.c_str()],
83
+ @"titleColor": @(subaction.titleColor),
84
+ @"subtitle": [NSString stringWithUTF8String:subaction.subtitle.c_str()],
85
+ @"state": [NSString stringWithUTF8String:subaction.state.c_str()],
86
+ @"image": [NSString stringWithUTF8String:subaction.image.c_str()],
87
+ @"imageColor": @(subaction.imageColor),
88
+ @"displayInline": @(subaction.displayInline),
89
+ @"attributes": @{
90
+ @"destructive": @(subaction.attributes.destructive),
91
+ @"disabled": @(subaction.attributes.disabled),
92
+ @"hidden": @(subaction.attributes.hidden),
93
+ },
94
+ };
95
+ [subactionsArray addObject:subactionDict];
96
+ }
97
+ }
98
+
99
+ // then convert the full actions object
100
+ NSDictionary *actionDict = @{
101
+ @"id": [NSString stringWithUTF8String:action.id.c_str()],
102
+ @"title": [NSString stringWithUTF8String:action.title.c_str()],
103
+ @"titleColor": @(action.titleColor),
104
+ @"subtitle": [NSString stringWithUTF8String:action.subtitle.c_str()],
105
+ @"state": [NSString stringWithUTF8String:action.state.c_str()],
106
+ @"image": [NSString stringWithUTF8String:action.image.c_str()],
107
+ @"imageColor": @(action.imageColor),
108
+ @"displayInline": @(action.displayInline),
109
+ @"attributes": @{
110
+ @"destructive": @(action.attributes.destructive),
111
+ @"disabled": @(action.attributes.disabled),
112
+ @"hidden": @(action.attributes.hidden),
113
+ },
114
+ @"subactions": subactionsArray,
115
+ };
116
+
117
+ [actionsArray addObject:actionDict];
118
+ }
119
+ return actionsArray;
120
+ }
121
+
122
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
123
+ {
124
+ const auto &oldViewProps = *std::static_pointer_cast<MenuViewProps const>(_props);
125
+ const auto &newViewProps = *std::static_pointer_cast<MenuViewProps const>(props);
126
+
127
+
128
+ if (oldViewProps.actionsHash != newViewProps.actionsHash) {
129
+ _view.actions = [self convertActionsToObjC: newViewProps.actions];
130
+ }
131
+
132
+ if (oldViewProps.title != newViewProps.title) {
133
+ _view.title = [NSString stringWithUTF8String:newViewProps.title.c_str()];
134
+ }
135
+
136
+ [super updateProps:props oldProps:oldProps];
137
+ }
138
+
139
+ Class<RCTComponentViewProtocol> MenuViewCls(void)
140
+ {
141
+ return MenuView.class;
142
+ }
143
+
144
+ @end
145
+ #endif
@@ -0,0 +1,11 @@
1
+
2
+ @objc(LegacyActionSheetView)
3
+ public class LegacyActionSheetView: ActionSheetView {
4
+ @objc var onPressAction: RCTDirectEventBlock?
5
+
6
+ @objc override func sendButtonAction(_ action: String) {
7
+ if let onPress = onPressAction {
8
+ onPress(["event":action])
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,13 @@
1
+ import UIKit
2
+ @available(iOS 14.0, *)
3
+ @objc(LegacyMenuViewImplementation)
4
+ public class LegacyMenuViewImplementation: MenuViewImplementation {
5
+ @objc var onPressAction: RCTDirectEventBlock?
6
+
7
+ @objc override func sendButtonAction(_ action: UIAction) {
8
+ if let onPress = onPressAction {
9
+ onPress(["event":action.identifier.rawValue])
10
+ }
11
+ }
12
+
13
+ }
@@ -9,15 +9,15 @@ import UIKit
9
9
 
10
10
 
11
11
  @objc(ActionSheetView)
12
- class ActionSheetView: UIView {
13
- @objc var onPressAction: RCTDirectEventBlock?
12
+ public class ActionSheetView: UIView {
13
+
14
14
  private var _title: String?
15
- @objc var title: NSString? {
15
+ @objc public var title: NSString? {
16
16
  didSet { self._title = title as? String }
17
17
  }
18
18
 
19
19
  private var _actions: [UIAlertAction] = []
20
- @objc var actions: [NSDictionary]? {
20
+ @objc public var actions: [NSDictionary]? {
21
21
  didSet {
22
22
  guard let actions = self.actions else {
23
23
  return
@@ -106,16 +106,14 @@ class ActionSheetView: UIView {
106
106
  }
107
107
 
108
108
  @objc func sendButtonAction(_ action: String) {
109
- if let onPress = onPressAction {
110
- onPress(["event":action])
111
- }
109
+ // NO-OP (should be overriden by parent)
112
110
  }
113
111
 
114
112
  required init?(coder: NSCoder) {
115
113
  fatalError("init(coder:) has not been implemented")
116
114
  }
117
115
 
118
- override func reactSetFrame(_ frame: CGRect) {
116
+ public override func reactSetFrame(_ frame: CGRect) {
119
117
  super.reactSetFrame(frame)
120
118
  }
121
119