Skip to content

Commit

Permalink
Remove logical styles shim
Browse files Browse the repository at this point in the history
See #35342
  • Loading branch information
necolas committed Nov 16, 2022
1 parent 21f6db7 commit dfeb49c
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @format
*/

import type {AccessibilityRole} from '../../Components/View/ViewAccessibility';
import type {
MeasureInWindowOnSuccessCallback,
MeasureLayoutOnSuccessCallback,
Expand All @@ -21,7 +22,6 @@ import dismissKeyboard from '../../Utilities/dismissKeyboard';
import Platform from '../../Utilities/Platform';
import StatusBar from '../StatusBar/StatusBar';
import View from '../View/View';
import type {AccessibilityRole} from '../../Components/View/ViewAccessibility';
import AndroidDrawerLayoutNativeComponent, {
Commands,
} from './AndroidDrawerLayoutNativeComponent';
Expand Down
17 changes: 5 additions & 12 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {TextInputType} from './TextInput.flow';

import usePressability from '../../Pressability/usePressability';
import flattenStyle from '../../StyleSheet/flattenStyle';
import processStyles from '../../StyleSheet/processStyles';
import StyleSheet, {
type ColorValue,
type TextStyleProp,
Expand Down Expand Up @@ -1420,19 +1419,15 @@ function InternalTextInput(props: Props): React.Node {
};
}

let style = flattenStyle(props.style);

if (Platform.OS === 'ios') {
const RCTTextInputView =
props.multiline === true
? RCTMultilineTextInputView
: RCTSinglelineTextInputView;

let style =
props.multiline === true
? [styles.multilineInput, props.style]
: props.style;

style = flattenStyle(style);
style = processStyles(style);
style = props.multiline === true ? [styles.multilineInput, style] : style;

const useOnChangeSync =
(props.unstable_onChangeSync || props.unstable_onChangeTextSync) &&
Expand Down Expand Up @@ -1465,9 +1460,6 @@ function InternalTextInput(props: Props): React.Node {
/>
);
} else if (Platform.OS === 'android') {
let style = flattenStyle(props.style);
style = processStyles(style);

const autoCapitalize = props.autoCapitalize || 'sentences';
const _accessibilityLabelledBy =
props?.['aria-labelledby'] ?? props?.accessibilityLabelledBy;
Expand Down Expand Up @@ -1635,11 +1627,12 @@ const ExportedForwardRef: React.AbstractComponent<
React.ElementRef<HostComponent<mixed>> & ImperativeMethods,
>,
) {
const style = flattenStyle(restProps.style);
let style = flattenStyle(restProps.style);

if (style?.verticalAlign != null) {
style.textAlignVertical =
verticalAlignToTextAlignVerticalMap[style.verticalAlign];
delete style.verticalAlign;
}

return (
Expand Down
5 changes: 1 addition & 4 deletions Libraries/Components/TextInput/__tests__/TextInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ describe('TextInput', () => {
onStartShouldSetResponder={[Function]}
rejectResponderTermination={true}
selection={null}
style={Object {}}
submitBehavior="blurAndSubmit"
text=""
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -254,7 +253,6 @@ describe('TextInput compat with web', () => {
onStartShouldSetResponder={[Function]}
rejectResponderTermination={true}
selection={null}
style={Object {}}
submitBehavior="blurAndSubmit"
tabIndex={0}
testID="testID"
Expand Down Expand Up @@ -394,7 +392,6 @@ describe('TextInput compat with web', () => {
rejectResponderTermination={true}
role="main"
selection={null}
style={Object {}}
submitBehavior="blurAndSubmit"
text=""
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -442,7 +439,7 @@ describe('TextInput compat with web', () => {
"backgroundColor": "white",
"display": "flex",
"flex": 1,
"marginStart": 10,
"marginInlineStart": 10,
"textAlignVertical": "center",
"userSelect": "none",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ exports[`TextInput tests should render as expected: should deep render when mock
onStartShouldSetResponder={[Function]}
rejectResponderTermination={true}
selection={null}
style={Object {}}
submitBehavior="blurAndSubmit"
text=""
underlineColorAndroid="transparent"
Expand Down Expand Up @@ -53,7 +52,6 @@ exports[`TextInput tests should render as expected: should deep render when not
onStartShouldSetResponder={[Function]}
rejectResponderTermination={true}
selection={null}
style={Object {}}
submitBehavior="blurAndSubmit"
text=""
underlineColorAndroid="transparent"
Expand Down
2 changes: 0 additions & 2 deletions Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import type {ViewProps} from './ViewPropTypes';

import flattenStyle from '../../StyleSheet/flattenStyle';
import processStyles from '../../StyleSheet/processStyles';
import TextAncestor from '../../Text/TextAncestor';
import {getAccessibilityRoleFromRole} from '../../Utilities/AcessibilityMapping';
import ViewNativeComponent from './ViewNativeComponent';
Expand Down Expand Up @@ -100,7 +99,6 @@ const View: React.AbstractComponent<
}

let style = flattenStyle(otherProps.style);
style = processStyles(style);

const newPointerEvents = style?.pointerEvents || pointerEvents;

Expand Down
10 changes: 2 additions & 8 deletions Libraries/Components/View/__tests__/View-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ describe('View', () => {
it('default render', () => {
const instance = render.create(<View />);

expect(instance.toJSON()).toMatchInlineSnapshot(`
<RCTView
style={Object {}}
/>
`);
expect(instance.toJSON()).toMatchInlineSnapshot(`<RCTView />`);
});

it('has displayName', () => {
Expand All @@ -47,7 +43,6 @@ describe('View compat with web', () => {
<RCTView
focusable={true}
nativeID="id"
style={Object {}}
testID="testID"
/>
`);
Expand Down Expand Up @@ -165,7 +160,6 @@ describe('View compat with web', () => {
aria-setsize={5}
aria-sort="ascending"
importantForAccessibility="no-hide-descendants"
style={Object {}}
/>
`);
});
Expand All @@ -189,7 +183,7 @@ describe('View compat with web', () => {
"backgroundColor": "white",
"display": "flex",
"flex": 1,
"marginStart": 10,
"marginInlineStart": 10,
"pointerEvents": "none",
}
}
Expand Down
4 changes: 0 additions & 4 deletions Libraries/Image/Image.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {ImageAndroid} from './Image.flow';
import type {ImageProps as ImagePropsType} from './ImageProps';

import flattenStyle from '../StyleSheet/flattenStyle';
import processStyles from '../StyleSheet/processStyles';
import StyleSheet from '../StyleSheet/StyleSheet';
import TextAncestor from '../Text/TextAncestor';
import ImageAnalyticsTagContext from './ImageAnalyticsTagContext';
Expand Down Expand Up @@ -159,16 +158,13 @@ const BaseImage = (props: ImagePropsType, forwardedRef) => {
const {width = props.width, height = props.height, uri} = source;
style = flattenStyle([{width, height}, styles.base, props.style]);
sources = [source];

if (uri === '') {
console.warn('source.uri should not be an empty string');
}
}

const {height, width, ...restProps} = props;

style = processStyles(style);

const {onLoadStart, onLoad, onLoadEnd, onError} = props;
const nativeProps = {
...restProps,
Expand Down
3 changes: 0 additions & 3 deletions Libraries/Image/Image.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {ImageIOS} from './Image.flow';
import type {ImageProps as ImagePropsType} from './ImageProps';

import flattenStyle from '../StyleSheet/flattenStyle';
import processStyles from '../StyleSheet/processStyles';
import StyleSheet from '../StyleSheet/StyleSheet';
import ImageAnalyticsTagContext from './ImageAnalyticsTagContext';
import ImageInjection from './ImageInjection';
Expand Down Expand Up @@ -138,8 +137,6 @@ const BaseImage = (props: ImagePropsType, forwardedRef) => {
// $FlowFixMe[prop-missing]
const tintColor = props.tintColor || style.tintColor;

style = processStyles(style);

if (props.children != null) {
throw new Error(
'The <Image> component cannot contain children. If you want to render content on top of the image, consider using the <ImageBackground> component or absolute positioning.',
Expand Down
78 changes: 0 additions & 78 deletions Libraries/StyleSheet/__tests__/processStyles-test.js

This file was deleted.

61 changes: 0 additions & 61 deletions Libraries/StyleSheet/processStyles.js

This file was deleted.

16 changes: 14 additions & 2 deletions Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import * as PressabilityDebug from '../Pressability/PressabilityDebug';
import usePressability from '../Pressability/usePressability';
import flattenStyle from '../StyleSheet/flattenStyle';
import processColor from '../StyleSheet/processColor';
import processStyles from '../StyleSheet/processStyles';
import {getAccessibilityRoleFromRole} from '../Utilities/AcessibilityMapping';
import Platform from '../Utilities/Platform';
import TextAncestor from './TextAncestor';
Expand Down Expand Up @@ -209,7 +208,6 @@ const Text: React.AbstractComponent<
});

style = flattenStyle(style);
style = processStyles(style);

if (typeof style?.fontWeight === 'number') {
style.fontWeight = style?.fontWeight.toString();
Expand All @@ -218,6 +216,13 @@ const Text: React.AbstractComponent<
let _selectable = restProps.selectable;
if (style?.userSelect != null) {
_selectable = userSelectToSelectableMap[style.userSelect];
delete style.userSelect;
}

if (style?.verticalAlign != null) {
style.textAlignVertical =
verticalAlignToTextAlignVerticalMap[style.verticalAlign];
delete style.verticalAlign;
}

const _hasOnPressOrOnLongPress =
Expand Down Expand Up @@ -300,4 +305,11 @@ const userSelectToSelectableMap = {
all: true,
};

const verticalAlignToTextAlignVerticalMap = {
auto: 'auto',
top: 'top',
bottom: 'bottom',
middle: 'center',
};

module.exports = Text;

0 comments on commit dfeb49c

Please sign in to comment.