@react-native-menu/menu 0.9.1 → 1.0.0
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.
- package/README.md +14 -2
- package/android/.project +11 -0
- package/android/build.gradle +69 -77
- package/android/gradle.properties +5 -4
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/reactnativemenu/MenuPackage.kt +1 -1
- package/android/src/main/java/com/reactnativemenu/MenuViewManager.kt +3 -3
- package/android/src/newarch/MenuViewManagerSpec.kt +21 -0
- package/android/src/oldarch/MenuViewManagerSpec.kt +9 -0
- package/ios/Menu-Bridging-Header.h +0 -2
- package/ios/MenuViewManager.mm +64 -0
- package/ios/NewArch/FabricActionSheetView.swift +11 -0
- package/ios/NewArch/FabricMenuViewImplementation.swift +20 -0
- package/ios/NewArch/FabricViewImplementationProtocol.swift +6 -0
- package/ios/NewArch/MenuView.h +19 -0
- package/ios/NewArch/MenuView.mm +155 -0
- package/ios/OldArch/LegacyActionSheetView.swift +11 -0
- package/ios/OldArch/LegacyMenuViewImplementation.swift +13 -0
- package/ios/{ActionSheetView.swift → Shared/ActionSheetView.swift} +6 -8
- package/ios/{MenuView.swift → Shared/MenuViewImplementation.swift} +9 -11
- package/ios/{RCTMenuItem.swift → Shared/RCTMenuItem.swift} +9 -1
- package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js +18 -0
- package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -0
- package/lib/commonjs/UIMenuView.android.js +1 -4
- package/lib/commonjs/UIMenuView.android.js.map +1 -1
- package/lib/commonjs/UIMenuView.ios.js +3 -6
- package/lib/commonjs/UIMenuView.ios.js.map +1 -1
- package/lib/commonjs/UIMenuView.js +3 -10
- package/lib/commonjs/UIMenuView.js.map +1 -1
- package/lib/commonjs/index.js +12 -14
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils.js +31 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js +12 -0
- package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -0
- package/lib/module/UIMenuView.android.js.map +1 -1
- package/lib/module/UIMenuView.ios.js +2 -3
- package/lib/module/UIMenuView.ios.js.map +1 -1
- package/lib/module/UIMenuView.js +0 -2
- package/lib/module/UIMenuView.js.map +1 -1
- package/lib/module/index.js +10 -10
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils.js +25 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts +44 -0
- package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/UIMenuView.android.d.ts +1 -0
- package/lib/typescript/src/UIMenuView.android.d.ts.map +1 -0
- package/lib/typescript/src/UIMenuView.d.ts +1 -0
- package/lib/typescript/src/UIMenuView.d.ts.map +1 -0
- package/lib/typescript/src/UIMenuView.ios.d.ts +3 -4
- package/lib/typescript/src/UIMenuView.ios.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +2 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +2 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/package.json +23 -12
- package/react-native-menu.podspec +26 -4
- package/src/NativeModuleSpecs/UIMenuNativeComponent.ts +55 -0
- package/src/UIMenuView.ios.tsx +2 -7
- package/src/index.tsx +8 -2
- package/src/types.ts +2 -0
- package/src/utils.ts +24 -0
- package/ios/Menu.xcodeproj/project.pbxproj +0 -297
- package/ios/RCTUIMenuManager.m +0 -27
- package/ios/RCTUIMenuManager.swift +0 -19
- /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={
|
|
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>
|
package/android/build.gradle
CHANGED
|
@@ -8,32 +8,63 @@ buildscript {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
dependencies {
|
|
11
|
-
classpath
|
|
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
|
-
|
|
18
|
-
|
|
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[
|
|
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[
|
|
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
|
-
|
|
30
|
-
|
|
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(
|
|
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
|
|
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(
|
|
105
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
124
106
|
|
|
125
107
|
dependencies {
|
|
126
|
-
//
|
|
127
|
-
|
|
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.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
Menu_kotlinVersion=1.7.0
|
|
2
|
+
Menu_minSdkVersion=21
|
|
3
|
+
Menu_targetSdkVersion=31
|
|
4
|
+
Menu_compileSdkVersion=31
|
|
5
|
+
Menu_ndkversion=21.4.7075529
|
|
@@ -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.
|
|
113
|
+
view.setHitSlopRect(null)
|
|
114
114
|
} else {
|
|
115
|
-
view.
|
|
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
|
+
}
|
|
@@ -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,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,155 @@
|
|
|
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
|
+
#ifdef RN_FABRIC_ENABLED
|
|
58
|
+
// If screen is already unmounted then there will be no event emitter
|
|
59
|
+
const auto eventEmitter = [self getEventEmitter];
|
|
60
|
+
if (eventEmitter != nullptr) {
|
|
61
|
+
|
|
62
|
+
eventEmitter->onPressAction(MenuViewEventEmitter::OnPressAction{
|
|
63
|
+
.event = [eventString UTF8String]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
#else
|
|
67
|
+
if (self.onPressAction) {
|
|
68
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
69
|
+
if (self.onPressAction) {
|
|
70
|
+
self.onPressAction(@{ @"event": eventString });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
#endif
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
Responsible for iterating through the C++ vector<struct> and convert each struct element to NSDictionary, then return it all in an NSArray
|
|
79
|
+
*/
|
|
80
|
+
- (NSMutableArray<NSDictionary *> *) convertActionsToObjC: (std::vector<MenuViewActionsStruct>) actions {
|
|
81
|
+
if (actions.size() == 0) {
|
|
82
|
+
return @[];
|
|
83
|
+
}
|
|
84
|
+
NSMutableArray<NSDictionary *> *actionsArray = [NSMutableArray arrayWithCapacity:actions.size()];
|
|
85
|
+
for (const MenuViewActionsStruct &action : actions) {
|
|
86
|
+
// first convert the subactions if they exist
|
|
87
|
+
NSMutableArray<NSDictionary *> *subactionsArray = [NSMutableArray arrayWithCapacity:actions.size()];
|
|
88
|
+
if (action.subactions.size() > 0) {
|
|
89
|
+
for (const MenuViewActionsSubactionsStruct &subaction : action.subactions) {
|
|
90
|
+
NSDictionary *subactionDict = @{
|
|
91
|
+
@"id": [NSString stringWithUTF8String:subaction.id.c_str()],
|
|
92
|
+
@"title": [NSString stringWithUTF8String:subaction.title.c_str()],
|
|
93
|
+
@"titleColor": @(subaction.titleColor),
|
|
94
|
+
@"subtitle": [NSString stringWithUTF8String:subaction.subtitle.c_str()],
|
|
95
|
+
@"state": [NSString stringWithUTF8String:subaction.state.c_str()],
|
|
96
|
+
@"image": [NSString stringWithUTF8String:subaction.image.c_str()],
|
|
97
|
+
@"imageColor": @(subaction.imageColor),
|
|
98
|
+
@"displayInline": @(subaction.displayInline),
|
|
99
|
+
@"attributes": @{
|
|
100
|
+
@"destructive": @(subaction.attributes.destructive),
|
|
101
|
+
@"disabled": @(subaction.attributes.disabled),
|
|
102
|
+
@"hidden": @(subaction.attributes.hidden),
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
[subactionsArray addObject:subactionDict];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// then convert the full actions object
|
|
110
|
+
NSDictionary *actionDict = @{
|
|
111
|
+
@"id": [NSString stringWithUTF8String:action.id.c_str()],
|
|
112
|
+
@"title": [NSString stringWithUTF8String:action.title.c_str()],
|
|
113
|
+
@"titleColor": @(action.titleColor),
|
|
114
|
+
@"subtitle": [NSString stringWithUTF8String:action.subtitle.c_str()],
|
|
115
|
+
@"state": [NSString stringWithUTF8String:action.state.c_str()],
|
|
116
|
+
@"image": [NSString stringWithUTF8String:action.image.c_str()],
|
|
117
|
+
@"imageColor": @(action.imageColor),
|
|
118
|
+
@"displayInline": @(action.displayInline),
|
|
119
|
+
@"attributes": @{
|
|
120
|
+
@"destructive": @(action.attributes.destructive),
|
|
121
|
+
@"disabled": @(action.attributes.disabled),
|
|
122
|
+
@"hidden": @(action.attributes.hidden),
|
|
123
|
+
},
|
|
124
|
+
@"subactions": subactionsArray,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
[actionsArray addObject:actionDict];
|
|
128
|
+
}
|
|
129
|
+
return actionsArray;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
|
133
|
+
{
|
|
134
|
+
const auto &oldViewProps = *std::static_pointer_cast<MenuViewProps const>(_props);
|
|
135
|
+
const auto &newViewProps = *std::static_pointer_cast<MenuViewProps const>(props);
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if (oldViewProps.actionsHash != newViewProps.actionsHash) {
|
|
139
|
+
_view.actions = [self convertActionsToObjC: newViewProps.actions];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (oldViewProps.title != newViewProps.title) {
|
|
143
|
+
_view.title = [NSString stringWithUTF8String:newViewProps.title.c_str()];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
[super updateProps:props oldProps:oldProps];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
Class<RCTComponentViewProtocol> MenuViewCls(void)
|
|
150
|
+
{
|
|
151
|
+
return MenuView.class;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@end
|
|
155
|
+
#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
|
-
|
|
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
|
-
|
|
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
|
|