Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add web compat unit tests and fixes #35316

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
552b7b9
feat: mapped layout props for view component
mayank-96 Sep 5, 2022
83a7b6c
fix: merge conflicts
mayank-96 Sep 5, 2022
3e98578
fix: moved map into the view component
mayank-96 Sep 6, 2022
9a43211
fix: mapped layout props for text component
mayank-96 Sep 6, 2022
656e6f6
fix: mapped layout props for image component
mayank-96 Sep 6, 2022
4c6f90f
fix: added layout props typings
mayank-96 Sep 6, 2022
57ac1e8
Merge remote-tracking branch 'upstream/main' into feat/mapping-layout…
mayank-96 Sep 7, 2022
1c90255
Merge remote-tracking branch 'upstream/main' into feat/mapping-layout…
mayank-96 Sep 9, 2022
fbd9b8e
Merge remote-tracking branch 'upstream/main' into feat/mapping-layout…
mayank-96 Sep 9, 2022
8d6689a
fix: shifted code to stylesheet dir
mayank-96 Sep 9, 2022
fc22eb2
fix: removed mapping from image
mayank-96 Sep 9, 2022
6cd3c52
Merge remote-tracking branch 'upstream/main' into feat/mapping-layout…
mayank-96 Sep 11, 2022
94d3284
wip
mayank-96 Sep 11, 2022
ef2dce7
Merge remote-tracking branch 'upstream/main' into feat/mapping-layout…
mayank-96 Sep 13, 2022
006bf1f
feat: added unit tests
mayank-96 Sep 15, 2022
b373081
fix: minor change
mayank-96 Sep 15, 2022
3300043
fix: requested changes
mayank-96 Sep 16, 2022
12b028a
Merge branch 'main' into feat/mapping-layout-props
necolas Nov 7, 2022
d47e1ba
Add unit tests for web compat View, Text, TextInput
necolas Nov 11, 2022
ce1c390
Merge branch 'main' into logical-style-props-and-tests
necolas Nov 11, 2022
21f6db7
Rename processLayoutProps
necolas Nov 12, 2022
dfeb49c
Remove logical styles shim
necolas Nov 16, 2022
6d6eca5
Fix missing 'id' and 'tabIndex' support for TextInput
necolas Nov 16, 2022
c60419b
Merge branch 'main' into logical-style-props-and-tests
necolas Nov 16, 2022
06718a6
Merge branch 'main' into logical-style-props-and-tests
necolas Nov 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
50 changes: 35 additions & 15 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,15 @@ const emptyFunctionThatReturnsTrue = () => true;
*
*/
function InternalTextInput(props: Props): React.Node {
const {
'aria-busy': ariaBusy,
'aria-checked': ariaChecked,
'aria-disabled': ariaDisabled,
'aria-expanded': ariaExpanded,
'aria-selected': ariaSelected,
accessibilityState,
} = props;

const inputRef = useRef<null | React.ElementRef<HostComponent<mixed>>>(null);

// Android sends a "onTextChanged" event followed by a "onSelectionChanged" event, for
Expand Down Expand Up @@ -1392,24 +1401,33 @@ function InternalTextInput(props: Props): React.Node {
// so omitting onBlur and onFocus pressability handlers here.
const {onBlur, onFocus, ...eventHandlers} = usePressability(config) || {};

const _accessibilityState = {
busy: props['aria-busy'] ?? props.accessibilityState?.busy,
checked: props['aria-checked'] ?? props.accessibilityState?.checked,
disabled: props['aria-disabled'] ?? props.accessibilityState?.disabled,
expanded: props['aria-expanded'] ?? props.accessibilityState?.expanded,
selected: props['aria-selected'] ?? props.accessibilityState?.selected,
};
let _accessibilityState;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should chose a different way than underscore to avoid shadowing. The ESLint rules special case variables starting with underscore as allowed to be possibly unused, and it is commonly used in the codebase for instance-like variables.

if (
accessibilityState != null ||
ariaBusy != null ||
ariaChecked != null ||
ariaDisabled != null ||
ariaExpanded != null ||
ariaSelected != null
) {
_accessibilityState = {
busy: ariaBusy ?? accessibilityState?.busy,
checked: ariaChecked ?? accessibilityState?.checked,
disabled: ariaDisabled ?? accessibilityState?.disabled,
expanded: ariaExpanded ?? accessibilityState?.expanded,
selected: ariaSelected ?? accessibilityState?.selected,
};
}

let style = flattenStyle(props.style);

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

const style =
props.multiline === true
? StyleSheet.flatten([styles.multilineInput, props.style])
: props.style;
style = props.multiline === true ? [styles.multilineInput, style] : style;

const useOnChangeSync =
(props.unstable_onChangeSync || props.unstable_onChangeTextSync) &&
Expand All @@ -1420,8 +1438,8 @@ function InternalTextInput(props: Props): React.Node {
ref={_setNativeRef}
{...props}
{...eventHandlers}
accessible={accessible}
accessibilityState={_accessibilityState}
accessible={accessible}
submitBehavior={submitBehavior}
caretHidden={caretHidden}
dataDetectorTypes={props.dataDetectorTypes}
Expand All @@ -1442,7 +1460,6 @@ function InternalTextInput(props: Props): React.Node {
/>
);
} else if (Platform.OS === 'android') {
const style = [props.style];
const autoCapitalize = props.autoCapitalize || 'sentences';
const _accessibilityLabelledBy =
props?.['aria-labelledby'] ?? props?.accessibilityLabelledBy;
Expand Down Expand Up @@ -1470,9 +1487,9 @@ function InternalTextInput(props: Props): React.Node {
ref={_setNativeRef}
{...props}
{...eventHandlers}
accessible={accessible}
accessibilityState={_accessibilityState}
accessibilityLabelledBy={_accessibilityLabelledBy}
accessible={accessible}
autoCapitalize={autoCapitalize}
submitBehavior={submitBehavior}
caretHidden={caretHidden}
Expand Down Expand Up @@ -1610,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 Expand Up @@ -1654,6 +1672,8 @@ const ExportedForwardRef: React.AbstractComponent<
);
});

ExportedForwardRef.displayName = 'TextInput';

/**
* Switch to `deprecated-react-native-prop-types` for compatibility with future
* releases. This is deprecated and will be removed in the future.
Expand Down
Loading