Fix types

This commit is contained in:
Nicolas Gallagher
2021-02-05 16:19:36 -08:00
parent 6efe1f90c2
commit 6a8369dd95
4 changed files with 61 additions and 45 deletions

View File

@@ -30,15 +30,8 @@ export type StateCallbackType = $ReadOnly<{|
type ViewStyleProp = $PropertyType<ViewProps, 'style'>;
type Props = $ReadOnly<{|
accessibilityLabel?: $PropertyType<ViewProps, 'accessibilityLabel'>,
accessibilityLiveRegion?: $PropertyType<ViewProps, 'accessibilityLiveRegion'>,
accessibilityRole?: $PropertyType<ViewProps, 'accessibilityRole'>,
accessibilityState?: $PropertyType<ViewProps, 'accessibilityState'>,
accessibilityValue?: $PropertyType<ViewProps, 'accessibilityValue'>,
accessible?: $PropertyType<ViewProps, 'accessible'>,
focusable?: ?boolean,
importantForAccessibility?: $PropertyType<ViewProps, 'importantForAccessibility'>,
type Props = {
...ViewProps,
children: React.Node | ((state: StateCallbackType) => React.Node),
// Duration (in milliseconds) from `onPressIn` before `onLongPress` is called.
delayLongPress?: ?number,
@@ -48,10 +41,6 @@ type Props = $ReadOnly<{|
delayPressOut?: ?number,
// Whether the press behavior is disabled.
disabled?: ?boolean,
// Called when the view blurs
onBlur?: $PropertyType<ViewProps, 'onBlur'>,
// Called when the view is focused
onFocus?: $PropertyType<ViewProps, 'onFocus'>,
// Called when the view is hovered
onHoverIn?: $PropertyType<HoverEventsConfig, 'onHoverStart'>,
// Called when the view is no longer hovered
@@ -69,13 +58,12 @@ type Props = $ReadOnly<{|
// Called when a touch is released, before `onPress`.
onPressOut?: $PropertyType<PressResponderConfig, 'onPressEnd'>,
style?: ViewStyleProp | ((state: StateCallbackType) => ViewStyleProp),
testID?: $PropertyType<ViewProps, 'testID'>,
/**
* Used only for documentation or testing (e.g. snapshot testing).
*/
testOnly_hovered?: ?boolean,
testOnly_pressed?: ?boolean
|}>;
};
/**
* Component used to build display components that should respond to whether the

View File

@@ -72,24 +72,15 @@ function shouldEmitScrollEvent(lastTick: number, eventThrottle: number) {
*/
const ScrollViewBase = forwardRef<Props, *>((props, forwardedRef) => {
const {
accessibilityLabel,
accessibilityRole,
accessibilityState,
children,
importantForAccessibility,
nativeID,
onLayout,
onScroll,
onTouchMove,
onWheel,
pointerEvents,
scrollEnabled = true,
scrollEventThrottle = 0,
showsHorizontalScrollIndicator,
showsVerticalScrollIndicator,
style,
dataSet,
testID
...rest
} = props;
const scrollState = useRef({ isScrolling: false, scrollLastTick: 0 });
@@ -153,25 +144,16 @@ const ScrollViewBase = forwardRef<Props, *>((props, forwardedRef) => {
return (
<View
accessibilityLabel={accessibilityLabel}
accessibilityRole={accessibilityRole}
accessibilityState={accessibilityState}
children={children}
dataSet={dataSet}
importantForAccessibility={importantForAccessibility}
nativeID={nativeID}
onLayout={onLayout}
{...rest}
onScroll={handleScroll}
onTouchMove={createPreventableScrollHandler(onTouchMove)}
onWheel={createPreventableScrollHandler(onWheel)}
pointerEvents={pointerEvents}
ref={useMergeRefs(scrollRef, forwardedRef)}
style={[
style,
!scrollEnabled && styles.scrollDisabled,
hideScrollbar && styles.hideScrollbar
]}
testID={testID}
/>
);
});

View File

@@ -25,14 +25,12 @@ export type Props = $ReadOnly<{|
accessibilityRole?: $PropertyType<ViewProps, 'accessibilityRole'>,
accessibilityState?: $PropertyType<ViewProps, 'accessibilityState'>,
accessibilityValue?: $PropertyType<ViewProps, 'accessibilityValue'>,
accessible?: $PropertyType<ViewProps, 'accessible'>,
children?: ?React.Node,
delayLongPress?: ?number,
delayPressIn?: ?number,
delayPressOut?: ?number,
disabled?: ?boolean,
focusable?: ?boolean,
importantForAccessibility?: $PropertyType<ViewProps, 'importantForAccessibility'>,
nativeID?: $PropertyType<ViewProps, 'nativeID'>,
onBlur?: $PropertyType<ViewProps, 'onBlur'>,
onFocus?: $PropertyType<ViewProps, 'onFocus'>,

View File

@@ -20,8 +20,60 @@ import type {
} from '../../types/styles';
type NumberOrString = number | string;
type OverscrollBehaviorValue = 'auto' | 'contain' | 'none';
type idRef = string;
type idRefList = idRef | Array<idRef>;
export type AccessibilityProps = {|
accessibilityActiveDescendant?: ?idRef,
accessibilityAtomic?: ?boolean,
accessibilityAutoComplete?: ?('none' | 'list' | 'inline' | 'both'),
accessibilityBusy?: ?boolean,
accessibilityChecked?: ?(boolean | 'mixed'),
accessibilityColumnCount?: ?number,
accessibilityColumnIndex?: ?number,
accessibilityColumnSpan?: ?number,
accessibilityControls?: ?idRefList,
accessibilityDescribedBy?: ?idRef,
accessibilityDetails?: ?idRef,
accessibilityDisabled?: ?boolean,
accessibilityErrorMessage?: ?idRef,
accessibilityExpanded?: ?boolean,
accessibilityFlowTo?: ?idRefList,
accessibilityHasPopup?: ?('dialog' | 'grid' | 'listbox' | 'menu' | 'tree' | false),
accessibilityHidden?: ?boolean,
accessibilityInvalid?: ?boolean,
accessibilityKeyShortcuts?: ?Array<string>,
accessibilityLabel?: ?string,
accessibilityLabelledBy?: ?idRefList,
accessibilityLevel?: ?number,
accessibilityLiveRegion?: ?('assertive' | 'none' | 'polite'),
accessibilityModal?: ?boolean,
accessibilityMultiline?: ?boolean,
accessibilityMultiSelectable?: ?boolean,
accessibilityOrientation?: ?('horizontal' | 'vertical'),
accessibilityOwns?: ?idRefList,
accessibilityPlaceholder?: ?string,
accessibilityPosInSet?: ?number,
accessibilityPressed?: ?(boolean | 'mixed'),
accessibilityReadOnly?: ?boolean,
accessibilityRequired?: ?boolean,
accessibilityRole?: ?string,
accessibilityRoleDescription?: ?string,
accessibilityRowCount?: ?number,
accessibilityRowIndex?: ?number,
accessibilityRowSpan?: ?number,
accessibilitySelected?: ?boolean,
accessibilitySetSize?: ?number,
accessibilitySort?: ?('ascending' | 'descending' | 'none' | 'other'),
accessibilityValueMax?: ?number,
accessibilityValueMin?: ?number,
accessibilityValueNow?: ?number,
accessibilityValueText?: ?string,
dataSet?: { ... },
focusable?: ?boolean,
nativeID?: ?string
|};
export type ViewStyle = {
...AnimationStyles,
@@ -59,9 +111,7 @@ export type ViewStyle = {
};
export type ViewProps = {
accessibilityLabel?: ?string,
accessibilityLiveRegion?: 'none' | 'polite' | 'assertive',
accessibilityRole?: ?string,
...AccessibilityProps,
accessibilityState?: {
busy?: ?boolean,
checked?: ?boolean | 'mixed',
@@ -82,9 +132,8 @@ export type ViewProps = {
now?: ?number,
text?: ?string
},
accessible?: boolean,
children?: ?any,
importantForAccessibility?: 'auto' | 'yes' | 'no' | 'no-hide-descendants',
focusable?: ?boolean,
nativeID?: ?string,
onBlur?: (e: any) => void,
onClick?: (e: any) => void,
@@ -133,6 +182,5 @@ export type ViewProps = {
onTouchStartCapture?: (e: any) => void,
onWheel?: (e: any) => void,
href?: ?string,
rel?: ?string,
target?: ?string
hrefAttrs?: ?{ download?: ?boolean, rel?: ?string, target?: ?string }
};