-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull PopupMenuAndroid out of React Native core
Summary: **History:** This component was originally introduced into React Native core in D52712758, to replace UIManagerModule.showPopupMenu(). **Problem:** But, React Native core should be lean. Adding this component to React Native bloats the core. **Changes:** So, this diff pulls PopupMenuAndroid out into its own package in the react-native GitHub repository. In the future, this will be migrated to a community package! Changelog: [Android][Removed] Move PopupMenu out of React Native core Reviewed By: NickGerleman Differential Revision: D53328110 fbshipit-source-id: 469d8dc3e756c06040c72e08fa004aafa1bd6e18
- Loading branch information
1 parent
e6e5822
commit 8bced4b
Showing
37 changed files
with
482 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/react-native-popup-menu-android/android/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
plugins { | ||
id("com.facebook.react") | ||
alias(libs.plugins.android.library) | ||
alias(libs.plugins.kotlin.android) | ||
} | ||
|
||
android { | ||
compileSdk = libs.versions.compileSdk.get().toInt() | ||
buildToolsVersion = libs.versions.buildTools.get() | ||
namespace = "com.facebook.react.popupmenu" | ||
|
||
defaultConfig { | ||
minSdk = libs.versions.minSdk.get().toInt() | ||
targetSdk = libs.versions.targetSdk.get().toInt() | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
kotlinOptions { jvmTarget = "17" } | ||
} | ||
|
||
dependencies { | ||
// Build React Native from source | ||
implementation(project(":packages:react-native:ReactAndroid")) | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/react-native-popup-menu-android/android/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# We want to have more fine grained control on the Java version for | ||
# ReactAndroid, therefore we disable RGNP Java version alignment mechanism | ||
react.internal.disableJavaVersionAlignment=true |
20 changes: 20 additions & 0 deletions
20
...droid/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/ComponentDescriptors.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
/** | ||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
* | ||
* Do not edit this file as changes may cause incorrect behavior and will be lost | ||
* once the code is regenerated. | ||
* | ||
* @generated by codegen project: GenerateComponentDescriptorH.js | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "ShadowNodes.h" | ||
#include <react/renderer/core/ConcreteComponentDescriptor.h> | ||
|
||
namespace facebook::react { | ||
|
||
using AndroidPopupMenuComponentDescriptor = ConcreteComponentDescriptor<AndroidPopupMenuShadowNode>; | ||
|
||
} // namespace facebook::react |
24 changes: 24 additions & 0 deletions
24
...id/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/EventEmitters.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
/** | ||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
* | ||
* Do not edit this file as changes may cause incorrect behavior and will be lost | ||
* once the code is regenerated. | ||
* | ||
* @generated by codegen project: GenerateEventEmitterCpp.js | ||
*/ | ||
|
||
#include "EventEmitters.h" | ||
|
||
|
||
namespace facebook::react { | ||
|
||
void AndroidPopupMenuEventEmitter::onSelectionChange(OnSelectionChange $event) const { | ||
dispatchEvent("selectionChange", [$event=std::move($event)](jsi::Runtime &runtime) { | ||
auto $payload = jsi::Object(runtime); | ||
$payload.setProperty(runtime, "item", $event.item); | ||
return $payload; | ||
}); | ||
} | ||
|
||
} // namespace facebook::react |
25 changes: 25 additions & 0 deletions
25
...roid/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/EventEmitters.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
/** | ||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
* | ||
* Do not edit this file as changes may cause incorrect behavior and will be lost | ||
* once the code is regenerated. | ||
* | ||
* @generated by codegen project: GenerateEventEmitterH.js | ||
*/ | ||
#pragma once | ||
|
||
#include <react/renderer/components/view/ViewEventEmitter.h> | ||
|
||
|
||
namespace facebook::react { | ||
class AndroidPopupMenuEventEmitter : public ViewEventEmitter { | ||
public: | ||
using ViewEventEmitter::ViewEventEmitter; | ||
|
||
struct OnSelectionChange { | ||
int item; | ||
}; | ||
void onSelectionChange(OnSelectionChange value) const; | ||
}; | ||
} // namespace facebook::react |
25 changes: 25 additions & 0 deletions
25
...nu-android/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/Props.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
/** | ||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
* | ||
* Do not edit this file as changes may cause incorrect behavior and will be lost | ||
* once the code is regenerated. | ||
* | ||
* @generated by codegen project: GeneratePropsCpp.js | ||
*/ | ||
|
||
#include "Props.h" | ||
#include <react/renderer/core/PropsParserContext.h> | ||
#include <react/renderer/core/propsConversions.h> | ||
|
||
namespace facebook::react { | ||
|
||
AndroidPopupMenuProps::AndroidPopupMenuProps( | ||
const PropsParserContext &context, | ||
const AndroidPopupMenuProps &sourceProps, | ||
const RawProps &rawProps): ViewProps(context, sourceProps, rawProps), | ||
|
||
menuItems(convertRawProp(context, rawProps, "menuItems", sourceProps.menuItems, {})) | ||
{} | ||
|
||
} // namespace facebook::react |
28 changes: 28 additions & 0 deletions
28
...menu-android/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/Props.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
/** | ||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
* | ||
* Do not edit this file as changes may cause incorrect behavior and will be lost | ||
* once the code is regenerated. | ||
* | ||
* @generated by codegen project: GeneratePropsH.js | ||
*/ | ||
#pragma once | ||
|
||
#include <react/renderer/components/view/ViewProps.h> | ||
#include <react/renderer/core/PropsParserContext.h> | ||
#include <vector> | ||
|
||
namespace facebook::react { | ||
|
||
class AndroidPopupMenuProps final : public ViewProps { | ||
public: | ||
AndroidPopupMenuProps() = default; | ||
AndroidPopupMenuProps(const PropsParserContext& context, const AndroidPopupMenuProps &sourceProps, const RawProps &rawProps); | ||
|
||
#pragma mark - Props | ||
|
||
std::vector<std::string> menuItems{}; | ||
}; | ||
|
||
} // namespace facebook::react |
17 changes: 17 additions & 0 deletions
17
...roid/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/ShadowNodes.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
/** | ||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
* | ||
* Do not edit this file as changes may cause incorrect behavior and will be lost | ||
* once the code is regenerated. | ||
* | ||
* @generated by codegen project: GenerateShadowNodeCpp.js | ||
*/ | ||
|
||
#include "ShadowNodes.h" | ||
|
||
namespace facebook::react { | ||
|
||
extern const char AndroidPopupMenuComponentName[] = "AndroidPopupMenu"; | ||
|
||
} // namespace facebook::react |
32 changes: 32 additions & 0 deletions
32
...ndroid/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/ShadowNodes.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
/** | ||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
* | ||
* Do not edit this file as changes may cause incorrect behavior and will be lost | ||
* once the code is regenerated. | ||
* | ||
* @generated by codegen project: GenerateShadowNodeH.js | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "EventEmitters.h" | ||
#include "Props.h" | ||
#include "States.h" | ||
#include <react/renderer/components/view/ConcreteViewShadowNode.h> | ||
#include <jsi/jsi.h> | ||
|
||
namespace facebook::react { | ||
|
||
JSI_EXPORT extern const char AndroidPopupMenuComponentName[]; | ||
|
||
/* | ||
* `ShadowNode` for <AndroidPopupMenu> component. | ||
*/ | ||
using AndroidPopupMenuShadowNode = ConcreteViewShadowNode< | ||
AndroidPopupMenuComponentName, | ||
AndroidPopupMenuProps, | ||
AndroidPopupMenuEventEmitter, | ||
AndroidPopupMenuState>; | ||
|
||
} // namespace facebook::react |
16 changes: 16 additions & 0 deletions
16
...u-android/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/States.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
/** | ||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
* | ||
* Do not edit this file as changes may cause incorrect behavior and will be lost | ||
* once the code is regenerated. | ||
* | ||
* @generated by codegen project: GenerateStateCpp.js | ||
*/ | ||
#include "States.h" | ||
|
||
namespace facebook::react { | ||
|
||
|
||
|
||
} // namespace facebook::react |
34 changes: 34 additions & 0 deletions
34
...enu-android/android/src/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/States.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). | ||
* | ||
* Do not edit this file as changes may cause incorrect behavior and will be lost | ||
* once the code is regenerated. | ||
* | ||
* @generated by codegen project: GenerateStateH.js | ||
*/ | ||
#pragma once | ||
|
||
#ifdef ANDROID | ||
#include <folly/dynamic.h> | ||
#include <react/renderer/mapbuffer/MapBuffer.h> | ||
#include <react/renderer/mapbuffer/MapBufferBuilder.h> | ||
#endif | ||
|
||
namespace facebook::react { | ||
|
||
class AndroidPopupMenuState { | ||
public: | ||
AndroidPopupMenuState() = default; | ||
|
||
#ifdef ANDROID | ||
AndroidPopupMenuState(AndroidPopupMenuState const &previousState, folly::dynamic data){}; | ||
folly::dynamic getDynamic() const { | ||
return {}; | ||
}; | ||
MapBuffer getMapBuffer() const { | ||
return MapBufferBuilder::EMPTY(); | ||
}; | ||
#endif | ||
}; | ||
|
||
} // namespace facebook::react |
56 changes: 56 additions & 0 deletions
56
...popup-menu-android/android/src/main/java/com/facebook/react/popupmenu/PopupMenuPackage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.popupmenu | ||
|
||
import com.facebook.react.BaseReactPackage | ||
import com.facebook.react.ViewManagerOnDemandReactPackage | ||
import com.facebook.react.bridge.ModuleSpec | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.module.annotations.ReactModuleList | ||
import com.facebook.react.module.model.ReactModuleInfoProvider | ||
import com.facebook.react.uimanager.ViewManager | ||
|
||
@ReactModuleList(nativeModules = arrayOf()) | ||
class PopupMenuPackage() : BaseReactPackage(), ViewManagerOnDemandReactPackage { | ||
private var viewManagersMap: Map<String, ModuleSpec>? = null | ||
|
||
override fun getModule(name: String, context: ReactApplicationContext): NativeModule? { | ||
return null | ||
} | ||
|
||
private fun getViewManagersMap(): Map<String, ModuleSpec> { | ||
val viewManagers = | ||
viewManagersMap | ||
?: mapOf( | ||
ReactPopupMenuManager.REACT_CLASS to | ||
ModuleSpec.viewManagerSpec({ ReactPopupMenuManager() })) | ||
viewManagersMap = viewManagers | ||
return viewManagers | ||
} | ||
|
||
protected override fun getViewManagers(context: ReactApplicationContext): List<ModuleSpec> { | ||
return ArrayList(getViewManagersMap().values) | ||
} | ||
|
||
override fun getViewManagerNames(context: ReactApplicationContext): Collection<String> { | ||
return getViewManagersMap().keys | ||
} | ||
|
||
override fun createViewManager( | ||
reactContext: ReactApplicationContext, | ||
viewManagerName: String | ||
): ViewManager<*, *>? { | ||
val spec: ModuleSpec? = getViewManagersMap().get(viewManagerName) | ||
return if (spec != null) (spec.getProvider().get() as ViewManager<*, *>) else null | ||
} | ||
|
||
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { | ||
return ReactModuleInfoProvider { emptyMap() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.