@react-native/popup-menu-android 0.74.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 (22) hide show
  1. package/android/build.gradle.kts +35 -0
  2. package/android/gradle.properties +3 -0
  3. package/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/ComponentDescriptors.h +20 -0
  4. package/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/EventEmitters.cpp +24 -0
  5. package/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/EventEmitters.h +25 -0
  6. package/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/Props.cpp +25 -0
  7. package/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/Props.h +28 -0
  8. package/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/ShadowNodes.cpp +17 -0
  9. package/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/ShadowNodes.h +32 -0
  10. package/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/States.cpp +16 -0
  11. package/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/States.h +34 -0
  12. package/android/src/main/java/com/facebook/react/popupmenu/PopupMenuPackage.kt +56 -0
  13. package/android/src/main/java/com/facebook/react/popupmenu/PopupMenuSelectionEvent.kt +36 -0
  14. package/android/src/main/java/com/facebook/react/popupmenu/ReactPopupMenuContainer.kt +49 -0
  15. package/android/src/main/java/com/facebook/react/popupmenu/ReactPopupMenuManager.kt +54 -0
  16. package/android/src/main/java/com/facebook/react/viewmanagers/AndroidPopupMenuManagerDelegate.java +41 -0
  17. package/android/src/main/java/com/facebook/react/viewmanagers/AndroidPopupMenuManagerInterface.java +19 -0
  18. package/js/PopupMenuAndroid.android.js +69 -0
  19. package/js/PopupMenuAndroid.d.ts +24 -0
  20. package/js/PopupMenuAndroid.js +54 -0
  21. package/js/PopupMenuAndroidNativeComponent.android.js +47 -0
  22. package/package.json +42 -0
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ plugins {
9
+ id("com.facebook.react")
10
+ alias(libs.plugins.android.library)
11
+ alias(libs.plugins.kotlin.android)
12
+ }
13
+
14
+ android {
15
+ compileSdk = libs.versions.compileSdk.get().toInt()
16
+ buildToolsVersion = libs.versions.buildTools.get()
17
+ namespace = "com.facebook.react.popupmenu"
18
+
19
+ defaultConfig {
20
+ minSdk = libs.versions.minSdk.get().toInt()
21
+ targetSdk = libs.versions.targetSdk.get().toInt()
22
+ }
23
+
24
+ compileOptions {
25
+ sourceCompatibility = JavaVersion.VERSION_17
26
+ targetCompatibility = JavaVersion.VERSION_17
27
+ }
28
+
29
+ kotlinOptions { jvmTarget = "17" }
30
+ }
31
+
32
+ dependencies {
33
+ // Build React Native from source
34
+ implementation(project(":packages:react-native:ReactAndroid"))
35
+ }
@@ -0,0 +1,3 @@
1
+ # We want to have more fine grained control on the Java version for
2
+ # ReactAndroid, therefore we disable RGNP Java version alignment mechanism
3
+ react.internal.disableJavaVersionAlignment=true
@@ -0,0 +1,20 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateComponentDescriptorH.js
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include "ShadowNodes.h"
14
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
15
+
16
+ namespace facebook::react {
17
+
18
+ using AndroidPopupMenuComponentDescriptor = ConcreteComponentDescriptor<AndroidPopupMenuShadowNode>;
19
+
20
+ } // namespace facebook::react
@@ -0,0 +1,24 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateEventEmitterCpp.js
9
+ */
10
+
11
+ #include "EventEmitters.h"
12
+
13
+
14
+ namespace facebook::react {
15
+
16
+ void AndroidPopupMenuEventEmitter::onSelectionChange(OnSelectionChange $event) const {
17
+ dispatchEvent("selectionChange", [$event=std::move($event)](jsi::Runtime &runtime) {
18
+ auto $payload = jsi::Object(runtime);
19
+ $payload.setProperty(runtime, "item", $event.item);
20
+ return $payload;
21
+ });
22
+ }
23
+
24
+ } // namespace facebook::react
@@ -0,0 +1,25 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateEventEmitterH.js
9
+ */
10
+ #pragma once
11
+
12
+ #include <react/renderer/components/view/ViewEventEmitter.h>
13
+
14
+
15
+ namespace facebook::react {
16
+ class AndroidPopupMenuEventEmitter : public ViewEventEmitter {
17
+ public:
18
+ using ViewEventEmitter::ViewEventEmitter;
19
+
20
+ struct OnSelectionChange {
21
+ int item;
22
+ };
23
+ void onSelectionChange(OnSelectionChange value) const;
24
+ };
25
+ } // namespace facebook::react
@@ -0,0 +1,25 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GeneratePropsCpp.js
9
+ */
10
+
11
+ #include "Props.h"
12
+ #include <react/renderer/core/PropsParserContext.h>
13
+ #include <react/renderer/core/propsConversions.h>
14
+
15
+ namespace facebook::react {
16
+
17
+ AndroidPopupMenuProps::AndroidPopupMenuProps(
18
+ const PropsParserContext &context,
19
+ const AndroidPopupMenuProps &sourceProps,
20
+ const RawProps &rawProps): ViewProps(context, sourceProps, rawProps),
21
+
22
+ menuItems(convertRawProp(context, rawProps, "menuItems", sourceProps.menuItems, {}))
23
+ {}
24
+
25
+ } // namespace facebook::react
@@ -0,0 +1,28 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GeneratePropsH.js
9
+ */
10
+ #pragma once
11
+
12
+ #include <react/renderer/components/view/ViewProps.h>
13
+ #include <react/renderer/core/PropsParserContext.h>
14
+ #include <vector>
15
+
16
+ namespace facebook::react {
17
+
18
+ class AndroidPopupMenuProps final : public ViewProps {
19
+ public:
20
+ AndroidPopupMenuProps() = default;
21
+ AndroidPopupMenuProps(const PropsParserContext& context, const AndroidPopupMenuProps &sourceProps, const RawProps &rawProps);
22
+
23
+ #pragma mark - Props
24
+
25
+ std::vector<std::string> menuItems{};
26
+ };
27
+
28
+ } // namespace facebook::react
@@ -0,0 +1,17 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateShadowNodeCpp.js
9
+ */
10
+
11
+ #include "ShadowNodes.h"
12
+
13
+ namespace facebook::react {
14
+
15
+ extern const char AndroidPopupMenuComponentName[] = "AndroidPopupMenu";
16
+
17
+ } // namespace facebook::react
@@ -0,0 +1,32 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateShadowNodeH.js
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include "EventEmitters.h"
14
+ #include "Props.h"
15
+ #include "States.h"
16
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
17
+ #include <jsi/jsi.h>
18
+
19
+ namespace facebook::react {
20
+
21
+ JSI_EXPORT extern const char AndroidPopupMenuComponentName[];
22
+
23
+ /*
24
+ * `ShadowNode` for <AndroidPopupMenu> component.
25
+ */
26
+ using AndroidPopupMenuShadowNode = ConcreteViewShadowNode<
27
+ AndroidPopupMenuComponentName,
28
+ AndroidPopupMenuProps,
29
+ AndroidPopupMenuEventEmitter,
30
+ AndroidPopupMenuState>;
31
+
32
+ } // namespace facebook::react
@@ -0,0 +1,16 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateStateCpp.js
9
+ */
10
+ #include "States.h"
11
+
12
+ namespace facebook::react {
13
+
14
+
15
+
16
+ } // namespace facebook::react
@@ -0,0 +1,34 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateStateH.js
8
+ */
9
+ #pragma once
10
+
11
+ #ifdef ANDROID
12
+ #include <folly/dynamic.h>
13
+ #include <react/renderer/mapbuffer/MapBuffer.h>
14
+ #include <react/renderer/mapbuffer/MapBufferBuilder.h>
15
+ #endif
16
+
17
+ namespace facebook::react {
18
+
19
+ class AndroidPopupMenuState {
20
+ public:
21
+ AndroidPopupMenuState() = default;
22
+
23
+ #ifdef ANDROID
24
+ AndroidPopupMenuState(AndroidPopupMenuState const &previousState, folly::dynamic data){};
25
+ folly::dynamic getDynamic() const {
26
+ return {};
27
+ };
28
+ MapBuffer getMapBuffer() const {
29
+ return MapBufferBuilder::EMPTY();
30
+ };
31
+ #endif
32
+ };
33
+
34
+ } // namespace facebook::react
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.popupmenu
9
+
10
+ import com.facebook.react.BaseReactPackage
11
+ import com.facebook.react.ViewManagerOnDemandReactPackage
12
+ import com.facebook.react.bridge.ModuleSpec
13
+ import com.facebook.react.bridge.NativeModule
14
+ import com.facebook.react.bridge.ReactApplicationContext
15
+ import com.facebook.react.module.annotations.ReactModuleList
16
+ import com.facebook.react.module.model.ReactModuleInfoProvider
17
+ import com.facebook.react.uimanager.ViewManager
18
+
19
+ @ReactModuleList(nativeModules = arrayOf())
20
+ class PopupMenuPackage() : BaseReactPackage(), ViewManagerOnDemandReactPackage {
21
+ private var viewManagersMap: Map<String, ModuleSpec>? = null
22
+
23
+ override fun getModule(name: String, context: ReactApplicationContext): NativeModule? {
24
+ return null
25
+ }
26
+
27
+ private fun getViewManagersMap(): Map<String, ModuleSpec> {
28
+ val viewManagers =
29
+ viewManagersMap
30
+ ?: mapOf(
31
+ ReactPopupMenuManager.REACT_CLASS to
32
+ ModuleSpec.viewManagerSpec({ ReactPopupMenuManager() }))
33
+ viewManagersMap = viewManagers
34
+ return viewManagers
35
+ }
36
+
37
+ protected override fun getViewManagers(context: ReactApplicationContext): List<ModuleSpec> {
38
+ return ArrayList(getViewManagersMap().values)
39
+ }
40
+
41
+ override fun getViewManagerNames(context: ReactApplicationContext): Collection<String> {
42
+ return getViewManagersMap().keys
43
+ }
44
+
45
+ override fun createViewManager(
46
+ reactContext: ReactApplicationContext,
47
+ viewManagerName: String
48
+ ): ViewManager<*, *>? {
49
+ val spec: ModuleSpec? = getViewManagersMap().get(viewManagerName)
50
+ return if (spec != null) (spec.getProvider().get() as ViewManager<*, *>) else null
51
+ }
52
+
53
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
54
+ return ReactModuleInfoProvider { emptyMap() }
55
+ }
56
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.popupmenu
9
+
10
+ import com.facebook.react.bridge.Arguments
11
+ import com.facebook.react.bridge.WritableMap
12
+ import com.facebook.react.uimanager.events.Event
13
+ import com.facebook.react.uimanager.events.RCTEventEmitter
14
+
15
+ public class PopupMenuSelectionEvent(surfaceId: Int, viewId: Int, private val item: Int) :
16
+ Event<PopupMenuSelectionEvent>(surfaceId, viewId) {
17
+
18
+ override fun getEventName(): String {
19
+ return EVENT_NAME
20
+ }
21
+
22
+ override fun getEventData(): WritableMap {
23
+ val eventData: WritableMap = Arguments.createMap()
24
+ eventData.putInt("target", viewTag)
25
+ eventData.putDouble("item", item.toDouble())
26
+ return eventData
27
+ }
28
+
29
+ override fun dispatch(rctEventEmitter: RCTEventEmitter) {
30
+ rctEventEmitter.receiveEvent(viewTag, eventName, eventData)
31
+ }
32
+
33
+ public companion object {
34
+ public const val EVENT_NAME: String = "topSelectionChange"
35
+ }
36
+ }
@@ -0,0 +1,49 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.popupmenu
9
+
10
+ import android.content.Context
11
+ import android.os.Build
12
+ import android.view.Menu
13
+ import android.widget.FrameLayout
14
+ import android.widget.PopupMenu
15
+ import com.facebook.react.bridge.ReactContext
16
+ import com.facebook.react.bridge.ReadableArray
17
+ import com.facebook.react.uimanager.UIManagerHelper
18
+
19
+ public class ReactPopupMenuContainer(context: Context) : FrameLayout(context) {
20
+ private var menuItems: ReadableArray? = null
21
+
22
+ public fun setMenuItems(items: ReadableArray?) {
23
+ menuItems = items
24
+ }
25
+
26
+ public fun showPopupMenu() {
27
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
28
+ val view = getChildAt(0)
29
+ val popupMenu = PopupMenu(context, view)
30
+ var menu = popupMenu.menu
31
+ val items = menuItems
32
+ if (items != null) {
33
+ for (i in 0 until items.size()) {
34
+ menu.add(Menu.NONE, Menu.NONE, i, items.getString(i))
35
+ }
36
+ }
37
+ popupMenu.setOnMenuItemClickListener { menuItem ->
38
+ val reactContext = context as ReactContext
39
+ val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id)
40
+ if (eventDispatcher != null) {
41
+ val surfaceId = UIManagerHelper.getSurfaceId(reactContext)
42
+ eventDispatcher.dispatchEvent(PopupMenuSelectionEvent(surfaceId, id, menuItem.order))
43
+ }
44
+ true
45
+ }
46
+ popupMenu.show()
47
+ }
48
+ }
49
+ }
@@ -0,0 +1,54 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.popupmenu
9
+
10
+ import com.facebook.react.bridge.ReadableArray
11
+ import com.facebook.react.module.annotations.ReactModule
12
+ import com.facebook.react.uimanager.ThemedReactContext
13
+ import com.facebook.react.uimanager.ViewGroupManager
14
+ import com.facebook.react.uimanager.annotations.ReactProp
15
+ import com.facebook.react.viewmanagers.AndroidPopupMenuManagerInterface
16
+
17
+ @ReactModule(name = ReactPopupMenuManager.REACT_CLASS)
18
+ public class ReactPopupMenuManager :
19
+ ViewGroupManager<ReactPopupMenuContainer>(),
20
+ AndroidPopupMenuManagerInterface<ReactPopupMenuContainer> {
21
+ override fun createViewInstance(reactContext: ThemedReactContext): ReactPopupMenuContainer {
22
+ return ReactPopupMenuContainer(reactContext)
23
+ }
24
+
25
+ @ReactProp(name = "menuItems")
26
+ override fun setMenuItems(view: ReactPopupMenuContainer, menuItems: ReadableArray?) {
27
+ view.setMenuItems(menuItems)
28
+ }
29
+
30
+ override fun getName(): String {
31
+ return REACT_CLASS
32
+ }
33
+
34
+ override fun receiveCommand(
35
+ view: ReactPopupMenuContainer,
36
+ commandId: String,
37
+ items: ReadableArray?
38
+ ) {
39
+ when (commandId) {
40
+ "show" -> show(view)
41
+ else -> {
42
+ // no-op
43
+ }
44
+ }
45
+ }
46
+
47
+ override fun show(popupMenu: ReactPopupMenuContainer) {
48
+ popupMenu.showPopupMenu()
49
+ }
50
+
51
+ public companion object {
52
+ public const val REACT_CLASS: String = "AndroidPopupMenu"
53
+ }
54
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GeneratePropsJavaDelegate.js
8
+ */
9
+
10
+ package com.facebook.react.viewmanagers;
11
+
12
+ import android.view.View;
13
+ import androidx.annotation.Nullable;
14
+ import com.facebook.react.bridge.ReadableArray;
15
+ import com.facebook.react.uimanager.BaseViewManagerDelegate;
16
+ import com.facebook.react.uimanager.BaseViewManagerInterface;
17
+
18
+ public class AndroidPopupMenuManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & AndroidPopupMenuManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
19
+ public AndroidPopupMenuManagerDelegate(U viewManager) {
20
+ super(viewManager);
21
+ }
22
+ @Override
23
+ public void setProperty(T view, String propName, @Nullable Object value) {
24
+ switch (propName) {
25
+ case "menuItems":
26
+ mViewManager.setMenuItems(view, (ReadableArray) value);
27
+ break;
28
+ default:
29
+ super.setProperty(view, propName, value);
30
+ }
31
+ }
32
+
33
+ @Override
34
+ public void receiveCommand(T view, String commandName, ReadableArray args) {
35
+ switch (commandName) {
36
+ case "show":
37
+ mViewManager.show(view);
38
+ break;
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GeneratePropsJavaInterface.js
8
+ */
9
+
10
+ package com.facebook.react.viewmanagers;
11
+
12
+ import android.view.View;
13
+ import androidx.annotation.Nullable;
14
+ import com.facebook.react.bridge.ReadableArray;
15
+
16
+ public interface AndroidPopupMenuManagerInterface<T extends View> {
17
+ void setMenuItems(T view, @Nullable ReadableArray value);
18
+ void show(T view);
19
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict-local
9
+ */
10
+
11
+ import type {RefObject} from 'react';
12
+ import type {HostComponent} from 'react-native';
13
+ import type {SyntheticEvent} from 'react-native/Libraries/Types/CoreEventTypes';
14
+
15
+ import PopupMenuAndroidNativeComponent, {
16
+ Commands,
17
+ } from './PopupMenuAndroidNativeComponent.android';
18
+ import nullthrows from 'nullthrows';
19
+ import * as React from 'react';
20
+ import {useCallback, useImperativeHandle, useRef} from 'react';
21
+
22
+ type PopupMenuSelectionEvent = SyntheticEvent<
23
+ $ReadOnly<{
24
+ item: number,
25
+ }>,
26
+ >;
27
+
28
+ export type PopupMenuAndroidInstance = {
29
+ +show: () => void,
30
+ };
31
+
32
+ type Props = {
33
+ menuItems: $ReadOnlyArray<string>,
34
+ onSelectionChange: number => void,
35
+ children: React.Node,
36
+ instanceRef: RefObject<?PopupMenuAndroidInstance>,
37
+ };
38
+
39
+ export default function PopupMenuAndroid({
40
+ menuItems,
41
+ onSelectionChange,
42
+ children,
43
+ instanceRef,
44
+ }: Props): React.Node {
45
+ const nativeRef = useRef<React.ElementRef<HostComponent<mixed>> | null>(null);
46
+ const _onSelectionChange = useCallback(
47
+ (event: PopupMenuSelectionEvent) => {
48
+ onSelectionChange(event.nativeEvent.item);
49
+ },
50
+ [onSelectionChange],
51
+ );
52
+
53
+ useImperativeHandle(instanceRef, ItemViewabilityInstance => {
54
+ return {
55
+ show() {
56
+ Commands.show(nullthrows(nativeRef.current));
57
+ },
58
+ };
59
+ });
60
+
61
+ return (
62
+ <PopupMenuAndroidNativeComponent
63
+ ref={nativeRef}
64
+ onSelectionChange={_onSelectionChange}
65
+ menuItems={menuItems}>
66
+ {children}
67
+ </PopupMenuAndroidNativeComponent>
68
+ );
69
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ */
9
+
10
+ import type * as React from 'react';
11
+ import {HostComponent} from 'react-native';
12
+
13
+ type PopupMenuAndroidInstance = {
14
+ show: () => void;
15
+ };
16
+
17
+ type Props = {
18
+ menuItems: Array<string>;
19
+ onSelectionChange: (number) => void;
20
+ children: React.ReactNode | undefined;
21
+ instanceRef: React.ElementRef<HostComponent<PopupMenuAndroidInstance>>;
22
+ };
23
+
24
+ declare class PopupMenuAndroid extends React.Component<Props> {}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict-local
9
+ */
10
+
11
+ import type {RefObject} from 'react';
12
+ import type {Node} from 'react';
13
+
14
+ import * as React from 'react';
15
+ import {StyleSheet, View} from 'react-native';
16
+
17
+ /**
18
+ * Common implementation for a simple stubbed view. Simply applies the view's styles to the inner
19
+ * View component and renders its children.
20
+ */
21
+ class UnimplementedView extends React.Component<{children: Node}> {
22
+ render(): React.Node {
23
+ return (
24
+ <View style={[styles.unimplementedView]}>{this.props.children}</View>
25
+ );
26
+ }
27
+ }
28
+
29
+ const styles = StyleSheet.create({
30
+ unimplementedView: __DEV__
31
+ ? {
32
+ alignSelf: 'flex-start',
33
+ borderColor: 'red',
34
+ borderWidth: 1,
35
+ }
36
+ : {},
37
+ });
38
+
39
+ export type PopupMenuAndroidInstance = {
40
+ +show: () => void,
41
+ };
42
+
43
+ type Props = {
44
+ menuItems: $ReadOnlyArray<string>,
45
+ onSelectionChange: number => void,
46
+ children: Node,
47
+ instanceRef: RefObject<?PopupMenuAndroidInstance>,
48
+ };
49
+
50
+ function PopupMenuAndroid(props: Props): Node {
51
+ return <UnimplementedView>{props.children}</UnimplementedView>;
52
+ }
53
+
54
+ export default PopupMenuAndroid;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';
12
+ import type {HostComponent} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes';
13
+ import type {
14
+ DirectEventHandler,
15
+ Int32,
16
+ } from 'react-native/Libraries/Types/CodegenTypes';
17
+
18
+ import * as React from 'react';
19
+ import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
20
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
21
+
22
+ type PopupMenuSelectionEvent = $ReadOnly<{
23
+ item: Int32,
24
+ }>;
25
+
26
+ type NativeProps = $ReadOnly<{
27
+ ...ViewProps,
28
+
29
+ //Props
30
+ menuItems?: ?$ReadOnlyArray<string>,
31
+
32
+ onSelectionChange?: DirectEventHandler<PopupMenuSelectionEvent>,
33
+ }>;
34
+
35
+ type ComponentType = HostComponent<NativeProps>;
36
+
37
+ interface NativeCommands {
38
+ +show: (viewRef: React.ElementRef<ComponentType>) => void;
39
+ }
40
+
41
+ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
42
+ supportedCommands: ['show'],
43
+ });
44
+
45
+ export default (codegenNativeComponent<NativeProps>(
46
+ 'AndroidPopupMenu',
47
+ ): HostComponent<NativeProps>);
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@react-native/popup-menu-android",
3
+ "version": "0.74.1",
4
+ "description": "PopupMenu for the Android platform",
5
+ "react-native": "js/PopupMenuAndroid",
6
+ "source": "js/PopupMenuAndroid",
7
+ "files": [
8
+ "js",
9
+ "android",
10
+ "!android/build",
11
+ "!**/__tests__",
12
+ "!**/__fixtures__",
13
+ "!**/__mocks__"
14
+ ],
15
+ "keywords": [
16
+ "react-native",
17
+ "android"
18
+ ],
19
+ "license": "MIT",
20
+ "devDependencies": {
21
+ "@react-native/codegen": "*"
22
+ },
23
+ "peerDependencies": {
24
+ "react": "*",
25
+ "react-native": "*"
26
+ },
27
+ "dependencies": {
28
+ "nullthrows": "^1.1.1"
29
+ },
30
+ "codegenConfig": {
31
+ "name": "ReactPopupMenuAndroidSpecs",
32
+ "type": "components",
33
+ "jsSrcsDir": "js",
34
+ "outputDir": {
35
+ "android": "android"
36
+ },
37
+ "includesGeneratedCode": true,
38
+ "android": {
39
+ "javaPackageName": "com.facebook.react.viewmanagers"
40
+ }
41
+ }
42
+ }