mirror of
https://github.com/react/react-native.git
synced 2026-09-28 13:23:09 +08:00
Summary: Pull Request resolved: https://github.com/react/react-native/pull/58603 Generate view configs and Codegen fixtures using supported React Native entry points or values derived from their exports. Generated view config modules can be emitted into arbitrary consumer package locations, so they cannot use a package-relative path back into React Native. Keep `ConditionallyIgnoredEventHandlers` centralized and expose it from the explicitly unstable compatibility entry point instead of duplicating its platform-specific semantics in generated output. Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D120717571 fbshipit-source-id: 9f3ea06d393eb8702bbb3ef2767c2d7c5fde1315
80 lines
1.9 KiB
JavaScript
80 lines
1.9 KiB
JavaScript
/**
|
|
* 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.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
*/
|
|
|
|
import type {RefObject} from 'react';
|
|
import type {HostInstance, NativeSyntheticEvent} from 'react-native';
|
|
|
|
import PopupMenuAndroidNativeComponent, {
|
|
Commands,
|
|
} from './PopupMenuAndroidNativeComponent.android';
|
|
import nullthrows from 'nullthrows';
|
|
import * as React from 'react';
|
|
import {useCallback, useImperativeHandle, useRef} from 'react';
|
|
|
|
type PopupMenuSelectionEvent = NativeSyntheticEvent<
|
|
Readonly<{
|
|
item: number,
|
|
}>,
|
|
>;
|
|
|
|
type PopupMenuDismissEvent = NativeSyntheticEvent<Readonly<{}>>;
|
|
|
|
export type PopupMenuAndroidInstance = {
|
|
readonly show: () => void,
|
|
};
|
|
|
|
type Props = {
|
|
menuItems: ReadonlyArray<string>,
|
|
onSelectionChange: number => void,
|
|
onDismiss?: () => void,
|
|
children: React.Node,
|
|
instanceRef: RefObject<?PopupMenuAndroidInstance>,
|
|
};
|
|
|
|
export default function PopupMenuAndroid({
|
|
menuItems,
|
|
onSelectionChange,
|
|
onDismiss,
|
|
children,
|
|
instanceRef,
|
|
}: Props): React.Node {
|
|
const nativeRef = useRef<HostInstance | null>(null);
|
|
const _onSelectionChange = useCallback(
|
|
(event: PopupMenuSelectionEvent) => {
|
|
onSelectionChange(event.nativeEvent.item);
|
|
},
|
|
[onSelectionChange],
|
|
);
|
|
const _onDismiss = useCallback(
|
|
(event: PopupMenuDismissEvent) => {
|
|
onDismiss?.();
|
|
},
|
|
[onDismiss],
|
|
);
|
|
|
|
useImperativeHandle(instanceRef, ItemViewabilityInstance => {
|
|
return {
|
|
show() {
|
|
Commands.show(nullthrows(nativeRef.current));
|
|
},
|
|
};
|
|
});
|
|
|
|
return (
|
|
<PopupMenuAndroidNativeComponent
|
|
ref={nativeRef}
|
|
onPopupMenuSelectionChange={_onSelectionChange}
|
|
onPopupMenuDismiss={_onDismiss}
|
|
menuItems={menuItems}>
|
|
{children}
|
|
</PopupMenuAndroidNativeComponent>
|
|
);
|
|
}
|