66 Easing ,
77 EmitterSubscription ,
88 findNodeHandle ,
9- I18nManager ,
109 Keyboard ,
1110 KeyboardEvent as RNKeyboardEvent ,
1211 LayoutRectangle ,
@@ -22,6 +21,7 @@ import {
2221} from 'react-native' ;
2322
2423import { APPROX_STATUSBAR_HEIGHT } from '../../constants' ;
24+ import { Direction , withLocaleDirection } from '../../core/Localization' ;
2525import { withInternalTheme } from '../../core/theming' ;
2626import type { $Omit , InternalTheme } from '../../types' ;
2727import { addEventListener } from '../../utils/addEventListener' ;
@@ -79,6 +79,10 @@ export type Props = {
7979 * testID to be used on tests.
8080 */
8181 testID ?: string ;
82+ /**
83+ * Indicates the text direction
84+ */
85+ direction : Direction ;
8286} ;
8387
8488type Layout = $Omit < $Omit < LayoutRectangle , 'x' > , 'y' > ;
@@ -155,9 +159,6 @@ const WINDOW_LAYOUT = Dimensions.get('window');
155159 * wrapping is not necessary if you use Paper's `Modal` instead.
156160 */
157161class Menu extends React . Component < Props , State > {
158- // @component ./MenuItem.tsx
159- static Item = MenuItem ;
160-
161162 static defaultProps = {
162163 statusBarHeight : APPROX_STATUSBAR_HEIGHT ,
163164 overlayAccessibilityLabel : 'Close menu' ,
@@ -418,6 +419,7 @@ class Menu extends React.Component<Props, State> {
418419 overlayAccessibilityLabel,
419420 keyboardShouldPersistTaps,
420421 testID,
422+ direction,
421423 } = this . props ;
422424
423425 const {
@@ -457,7 +459,14 @@ class Menu extends React.Component<Props, State> {
457459 ] ;
458460
459461 // We need to translate menu while animating scale to imitate transform origin for scale animation
460- const positionTransforms = [ ] ;
462+ const positionTransforms : (
463+ | {
464+ translateX : Animated . AnimatedInterpolation < string | number > ;
465+ }
466+ | {
467+ translateY : Animated . AnimatedInterpolation < string | number > ;
468+ }
469+ ) [ ] = [ ] ;
461470
462471 // Check if menu fits horizontally and if not align it to right.
463472 if ( left <= windowLayout . width - menuLayout . width - SCREEN_INDENT ) {
@@ -598,10 +607,10 @@ class Menu extends React.Component<Props, State> {
598607 ...( scrollableMenuHeight ? { height : scrollableMenuHeight } : { } ) ,
599608 } ;
600609
601- const positionStyle = {
610+ const positionStyle = ( isRTL : boolean ) => ( {
602611 top : this . isCoordinate ( anchor ) ? top : top + additionalVerticalValue ,
603- ...( I18nManager . getConstants ( ) . isRTL ? { right : left } : { left } ) ,
604- } ;
612+ ...( isRTL ? { right : left } : { left } ) ,
613+ } ) ;
605614
606615 return (
607616 < View
@@ -626,7 +635,11 @@ class Menu extends React.Component<Props, State> {
626635 } }
627636 collapsable = { false }
628637 accessibilityViewIsModal = { visible }
629- style = { [ styles . wrapper , positionStyle , style ] }
638+ style = { [
639+ styles . wrapper ,
640+ positionStyle ( direction === 'rtl' ) ,
641+ style ,
642+ ] }
630643 pointerEvents = { visible ? 'box-none' : 'none' }
631644 onAccessibilityEscape = { onDismiss }
632645 >
@@ -671,4 +684,7 @@ const styles = StyleSheet.create({
671684 } ,
672685} ) ;
673686
674- export default withInternalTheme ( Menu ) ;
687+ export default Object . assign ( withInternalTheme ( withLocaleDirection ( Menu ) ) , {
688+ // @component ./MenuItem.tsx
689+ Item : MenuItem ,
690+ } ) ;
0 commit comments