mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary:
This PR adds mapping for layout props, it maps
marginInlineStart: 'marginStart',
marginInlineEnd: 'marginEnd',
marginBlockStart: 'marginTop',
marginBlockEnd: 'marginBottom',
marginBlock: 'marginVertical',
marginInline: 'marginHorizontal',
paddingInlineStart: 'paddingStart',
paddingInlineEnd: 'paddingEnd',
paddingBlockStart: 'paddingTop',
paddingBlockEnd: 'paddingBottom',
paddingBlock: 'paddingVertical',
paddingInline: 'paddingHorizontal',
as requested on https://github.com/facebook/react-native/issues/34425
## Changelog
<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[General][Added] - Added CSS logical properties by mapping layout props.
Pull Request resolved: https://github.com/facebook/react-native/pull/34590
Test Plan:
```js
<View
style={[
{
marginBlockStart: 5, // maps to "marginTop"
borderWidth: 1,
borderRadius: 5,
padding: 5,
}
]}>
<Text style={{fontSize: 11}}>Hello World!</Text>
</View>
```
Reviewed By: cipolleschi
Differential Revision: D41108750
Pulled By: necolas
fbshipit-source-id: 870b9b58a740aba12290a0604a9f6b52aa52de4c
125 lines
3.8 KiB
JavaScript
125 lines
3.8 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.
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
import type {ViewProps} from './ViewPropTypes';
|
|
|
|
import flattenStyle from '../../StyleSheet/flattenStyle';
|
|
import processLayoutProps from '../../StyleSheet/processStyles';
|
|
import TextAncestor from '../../Text/TextAncestor';
|
|
import {getAccessibilityRoleFromRole} from '../../Utilities/AcessibilityMapping';
|
|
import ViewNativeComponent from './ViewNativeComponent';
|
|
import * as React from 'react';
|
|
|
|
export type Props = ViewProps;
|
|
|
|
/**
|
|
* The most fundamental component for building a UI, View is a container that
|
|
* supports layout with flexbox, style, some touch handling, and accessibility
|
|
* controls.
|
|
*
|
|
* @see https://reactnative.dev/docs/view
|
|
*/
|
|
const View: React.AbstractComponent<
|
|
ViewProps,
|
|
React.ElementRef<typeof ViewNativeComponent>,
|
|
> = React.forwardRef(
|
|
(
|
|
{
|
|
accessibilityElementsHidden,
|
|
accessibilityLabel,
|
|
accessibilityLabelledBy,
|
|
accessibilityLiveRegion,
|
|
accessibilityRole,
|
|
accessibilityState,
|
|
accessibilityValue,
|
|
'aria-busy': ariaBusy,
|
|
'aria-checked': ariaChecked,
|
|
'aria-disabled': ariaDisabled,
|
|
'aria-expanded': ariaExpanded,
|
|
'aria-hidden': ariaHidden,
|
|
'aria-label': ariaLabel,
|
|
'aria-labelledby': ariaLabelledBy,
|
|
'aria-live': ariaLive,
|
|
'aria-selected': ariaSelected,
|
|
'aria-valuemax': ariaValueMax,
|
|
'aria-valuemin': ariaValueMin,
|
|
'aria-valuenow': ariaValueNow,
|
|
'aria-valuetext': ariaValueText,
|
|
focusable,
|
|
id,
|
|
importantForAccessibility,
|
|
nativeID,
|
|
pointerEvents,
|
|
role,
|
|
tabIndex,
|
|
...otherProps
|
|
}: ViewProps,
|
|
forwardedRef,
|
|
) => {
|
|
const _accessibilityLabelledBy =
|
|
ariaLabelledBy?.split(/\s*,\s*/g) ?? accessibilityLabelledBy;
|
|
|
|
const _accessibilityState = {
|
|
busy: ariaBusy ?? accessibilityState?.busy,
|
|
checked: ariaChecked ?? accessibilityState?.checked,
|
|
disabled: ariaDisabled ?? accessibilityState?.disabled,
|
|
expanded: ariaExpanded ?? accessibilityState?.expanded,
|
|
selected: ariaSelected ?? accessibilityState?.selected,
|
|
};
|
|
|
|
const _accessibilityValue = {
|
|
max: ariaValueMax ?? accessibilityValue?.max,
|
|
min: ariaValueMin ?? accessibilityValue?.min,
|
|
now: ariaValueNow ?? accessibilityValue?.now,
|
|
text: ariaValueText ?? accessibilityValue?.text,
|
|
};
|
|
|
|
let style = flattenStyle(otherProps.style);
|
|
style = processLayoutProps(style);
|
|
|
|
const newPointerEvents = style?.pointerEvents || pointerEvents;
|
|
|
|
return (
|
|
<TextAncestor.Provider value={false}>
|
|
<ViewNativeComponent
|
|
{...otherProps}
|
|
accessibilityLiveRegion={
|
|
ariaLive === 'off' ? 'none' : ariaLive ?? accessibilityLiveRegion
|
|
}
|
|
accessibilityLabel={ariaLabel ?? accessibilityLabel}
|
|
focusable={tabIndex !== undefined ? !tabIndex : focusable}
|
|
accessibilityState={_accessibilityState}
|
|
accessibilityRole={
|
|
role ? getAccessibilityRoleFromRole(role) : accessibilityRole
|
|
}
|
|
accessibilityElementsHidden={
|
|
ariaHidden ?? accessibilityElementsHidden
|
|
}
|
|
accessibilityLabelledBy={_accessibilityLabelledBy}
|
|
accessibilityValue={_accessibilityValue}
|
|
importantForAccessibility={
|
|
ariaHidden === true
|
|
? 'no-hide-descendants'
|
|
: importantForAccessibility
|
|
}
|
|
nativeID={id ?? nativeID}
|
|
style={style}
|
|
pointerEvents={newPointerEvents}
|
|
ref={forwardedRef}
|
|
/>
|
|
</TextAncestor.Provider>
|
|
);
|
|
},
|
|
);
|
|
|
|
View.displayName = 'View';
|
|
|
|
module.exports = View;
|