Skip to content

Commit

Permalink
Merge branch 'main' into improve-lineheight-calc-ios
Browse files Browse the repository at this point in the history
  • Loading branch information
ArekChr committed Oct 22, 2024
2 parents 2ec676c + 3dfe22b commit 848e4b2
Show file tree
Hide file tree
Showing 67 changed files with 2,190 additions and 284 deletions.
3 changes: 2 additions & 1 deletion packages/react-native-codegen/src/CodegenSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type MixedTypeAnnotation = $ReadOnly<{
type: 'MixedTypeAnnotation',
}>;

type EventEmitterTypeAnnotation = $ReadOnly<{
export type EventEmitterTypeAnnotation = $ReadOnly<{
type: 'EventEmitterTypeAnnotation',
typeAnnotation: NativeModuleEventEmitterTypeAnnotation | $FlowFixMe,
}>;
Expand Down Expand Up @@ -424,4 +424,5 @@ export type CompleteTypeAnnotation =
| NativeModuleTypeAnnotation
| NativeModuleFunctionTypeAnnotation
| NullableTypeAnnotation<NativeModuleTypeAnnotation>
| EventEmitterTypeAnnotation
| UnsafeAnyTypeAnnotation;
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ export type StrictAnimatedProps<Props: {...}> = $ReadOnly<{
passthroughAnimatedPropExplicitValues?: ?Props,
}>;

export type AnimatedComponentType<
Props: {...},
+Instance = mixed,
> = React.AbstractComponent<AnimatedProps<Props>, Instance>;
export type AnimatedComponentType<Props: {...}, +Instance = mixed> = component(
ref: React.RefSetter<Instance>,
...AnimatedProps<Props>
);

export type StrictAnimatedComponentType<
Props: {...},
+Instance = mixed,
> = React.AbstractComponent<StrictAnimatedProps<Props>, Instance>;
> = component(ref: React.RefSetter<Instance>, ...StrictAnimatedProps<Props>);

export default function createAnimatedComponent<TProps: {...}, TInstance>(
Component: React.AbstractComponent<TProps, TInstance>,
Component: component(ref: React.RefSetter<TInstance>, ...TProps),
): AnimatedComponentType<TProps, TInstance> {
return unstable_createAnimatedComponentWithAllowlist(Component, null);
}
Expand All @@ -55,7 +55,7 @@ export function unstable_createAnimatedComponentWithAllowlist<
TProps: {...},
TInstance,
>(
Component: React.AbstractComponent<TProps, TInstance>,
Component: component(ref: React.RefSetter<TInstance>, ...TProps),
allowlist: ?AnimatedPropsAllowlist,
): StrictAnimatedComponentType<TProps, TInstance> {
const AnimatedComponent = React.forwardRef<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const ActivityIndicator = (
*/

const ActivityIndicatorWithRef: component(
ref: React.RefSetter<HostComponent<mixed>>,
ref: React.RefSetter<HostComponent<empty>>,
...props: Props
) = React.forwardRef(ActivityIndicator);
ActivityIndicatorWithRef.displayName = 'ActivityIndicator';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import type {HostComponent} from '../../../Renderer/shims/ReactNativeTypes';
import requireNativeComponent from '../../../ReactNative/requireNativeComponent';
import * as React from 'react';

const RCTRefreshControl: HostComponent<mixed> =
requireNativeComponent<mixed>('RCTRefreshControl');
const RCTRefreshControl: HostComponent<{}> = requireNativeComponent<{}>(
'RCTRefreshControl',
);

class RefreshControlMock extends React.Component<{...}> {
static latestRef: ?RefreshControlMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,10 @@ type AndroidProps = $ReadOnly<{|
fadingEdgeLength?: ?number,
|}>;

type StickyHeaderComponentType = React.AbstractComponent<
ScrollViewStickyHeaderProps,
$ReadOnly<interface {setNextHeaderY: number => void}>,
>;
type StickyHeaderComponentType = component(
ref?: React.RefSetter<$ReadOnly<interface {setNextHeaderY: number => void}>>,
...ScrollViewStickyHeaderProps
);

export type Props = $ReadOnly<{|
...ViewProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {Double} from '../../Types/CodegenTypes';
import codegenNativeCommands from '../../Utilities/codegenNativeCommands';
import * as React from 'react';

type ScrollViewNativeComponentType = HostComponent<mixed>;
type ScrollViewNativeComponentType = HostComponent<{...}>;
interface NativeCommands {
+flashScrollIndicators: (
viewRef: React.ElementRef<ScrollViewNativeComponentType>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ if (__DEV__) {
}
export default ScrollViewContext;

// $FlowFixMe[incompatible-type] frozen objects are readonly
export const HORIZONTAL: Value = Object.freeze({horizontal: true});
// $FlowFixMe[incompatible-type] frozen objects are readonly
export const VERTICAL: Value = Object.freeze({horizontal: false});
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ const ScrollViewStickyHeaderWithForwardedRef: component(
: null;

return (
/* $FlowFixMe[prop-missing] passthroughAnimatedPropExplicitValues isn't properly
included in the Animated.View flow type. */
<Animated.View
collapsable={false}
nativeID={props.nativeID}
onLayout={_onLayout}
/* $FlowFixMe[prop-missing] passthroughAnimatedPropExplicitValues isn't properly
included in the Animated.View flow type. */
ref={ref}
style={[
child.props.style,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type Props = $ReadOnly<{|
backgroundColor?: ?ColorValue,
|}>;

const InputAccessoryView: React.AbstractComponent<Props> = (props: Props) => {
const InputAccessoryView: React.ComponentType<Props> = (props: Props) => {
const {width} = useWindowDimensions();

if (Platform.OS === 'ios') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as NativeComponentRegistry from '../../NativeComponent/NativeComponentR
import codegenNativeCommands from '../../Utilities/codegenNativeCommands';
import RCTTextInputViewConfig from './RCTTextInputViewConfig';

type NativeType = HostComponent<mixed>;
type NativeType = HostComponent<{...}>;

type NativeCommands = TextInputNativeCommands<NativeType>;

Expand All @@ -35,11 +35,11 @@ export const __INTERNAL_VIEW_CONFIG: PartialViewConfig = {
},
};

const MultilineTextInputNativeComponent: HostComponent<mixed> =
NativeComponentRegistry.get<mixed>(
const MultilineTextInputNativeComponent: HostComponent<{...}> =
NativeComponentRegistry.get<{...}>(
'RCTMultilineTextInputView',
() => __INTERNAL_VIEW_CONFIG,
);

// flowlint-next-line unclear-type:off
export default ((MultilineTextInputNativeComponent: any): HostComponent<mixed>);
export default ((MultilineTextInputNativeComponent: any): HostComponent<{...}>);
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as NativeComponentRegistry from '../../NativeComponent/NativeComponentR
import codegenNativeCommands from '../../Utilities/codegenNativeCommands';
import RCTTextInputViewConfig from './RCTTextInputViewConfig';

type NativeType = HostComponent<mixed>;
type NativeType = HostComponent<{...}>;

type NativeCommands = TextInputNativeCommands<NativeType>;

Expand All @@ -31,11 +31,13 @@ export const __INTERNAL_VIEW_CONFIG: PartialViewConfig = {
...RCTTextInputViewConfig,
};

const SinglelineTextInputNativeComponent: HostComponent<mixed> =
NativeComponentRegistry.get<mixed>(
const SinglelineTextInputNativeComponent: HostComponent<{...}> =
NativeComponentRegistry.get<{...}>(
'RCTSinglelineTextInputView',
() => __INTERNAL_VIEW_CONFIG,
);

// flowlint-next-line unclear-type:off
export default ((SinglelineTextInputNativeComponent: any): HostComponent<mixed>);
export default ((SinglelineTextInputNativeComponent: any): HostComponent<{
...
}>);
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,10 @@ type ImperativeMethods = $ReadOnly<{|
* or control this param programmatically with native code.
*
*/
type InternalTextInput = (props: Props) => React.Node;
type InternalTextInput = component(
ref: React.RefSetter<$ReadOnly<{...HostInstance, ...ImperativeMethods}>>,
...Props
);

export type TextInputComponentStatics = $ReadOnly<{|
State: $ReadOnly<{|
Expand All @@ -1097,11 +1100,4 @@ export type TextInputComponentStatics = $ReadOnly<{|
|}>,
|}>;

export type TextInputType = React.AbstractComponent<
React.ElementConfig<InternalTextInput>,
$ReadOnly<{|
...HostInstance,
...ImperativeMethods,
|}>,
> &
TextInputComponentStatics;
export type TextInputType = InternalTextInput & TextInputComponentStatics;
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class TouchableBounce extends React.Component<Props, State> {
this.props.onPress !== undefined &&
!this.props.disabled
}
// $FlowFixMe[prop-missing]
ref={this.props.hostRef}
{...eventHandlersWithoutBlurAndFocus}>
{this.props.children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class TouchableOpacity extends React.Component<Props, State> {
this.props.onPress !== undefined &&
!this.props.disabled
}
// $FlowFixMe[prop-missing]
ref={this.props.hostRef}
{...eventHandlersWithoutBlurAndFocus}>
{this.props.children}
Expand Down
14 changes: 7 additions & 7 deletions packages/react-native/Libraries/Lists/SectionListModern.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
SectionBase as _SectionBase,
VirtualizedSectionListProps,
} from '@react-native/virtualized-lists';
import type {AbstractComponent, ElementRef} from 'react';
import type {ElementRef} from 'react';

import Platform from '../Utilities/Platform';
import {VirtualizedSectionList} from '@react-native/virtualized-lists';
Expand Down Expand Up @@ -93,7 +93,7 @@ type OptionalProps<SectionT: SectionBase<any>> = {|
removeClippedSubviews?: boolean,
|};

export type Props<SectionT> = {|
export type Props<SectionT: SectionBase<any>> = $ReadOnly<{|
...$Diff<
VirtualizedSectionListProps<SectionT>,
{
Expand All @@ -115,7 +115,7 @@ export type Props<SectionT> = {|
>,
...RequiredProps<SectionT>,
...OptionalProps<SectionT>,
|};
|}>;

/**
* A performant interface for rendering sectioned lists, supporting the most handy features:
Expand Down Expand Up @@ -172,10 +172,10 @@ export type Props<SectionT> = {|
* Alternatively, you can provide a custom `keyExtractor` prop.
*
*/
const SectionList: AbstractComponent<Props<SectionBase<any>>, any> = forwardRef<
Props<SectionBase<any>>,
any,
>((props, ref) => {
const SectionList: component(
ref?: React.RefSetter<any>,
...Props<SectionBase<any>>
) = forwardRef<Props<SectionBase<any>>, any>((props, ref) => {
const propsWithDefaults = {
stickySectionHeadersEnabled: Platform.OS === 'ios',
...props,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/Libraries/LogBox/Data/LogBoxData.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ type State = $ReadOnly<{|
selectedLogIndex: number,
|}>;

type SubscribedComponent = React.AbstractComponent<
type SubscribedComponent = React.ComponentType<
$ReadOnly<{|
logs: $ReadOnlyArray<LogBoxLog>,
isDisabled: boolean,
Expand All @@ -431,7 +431,7 @@ type SubscribedComponent = React.AbstractComponent<

export function withSubscription(
WrappedComponent: SubscribedComponent,
): React.AbstractComponent<{||}> {
): React.ComponentType<{||}> {
class LogBoxStateSubscription extends React.Component<Props, State> {
static getDerivedStateFromError(): {hasError: boolean} {
return {hasError: true};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ export class _LogBoxInspectorContainer extends React.Component<Props> {

export default (LogBoxData.withSubscription(
_LogBoxInspectorContainer,
): React.AbstractComponent<{||}>);
): React.ComponentType<{||}>);
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ const styles = StyleSheet.create({

export default (LogBoxData.withSubscription(
_LogBoxNotificationContainer,
): React.AbstractComponent<{||}>);
): React.ComponentType<{||}>);
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Props = $ReadOnly<{
level: LogLevel,
}>;

const LogBoxInspectorHeaderSafeArea: React.AbstractComponent<ViewProps> =
const LogBoxInspectorHeaderSafeArea: React.ComponentType<ViewProps> =
Platform.OS === 'android' ? View : SafeAreaView;

export default function LogBoxInspectorHeader(props: Props): React.Node {
Expand Down
5 changes: 2 additions & 3 deletions packages/react-native/Libraries/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ const styles = StyleSheet.create({
},
});

const ExportedModal: React.AbstractComponent<
React.ElementConfig<typeof Modal>,
> = ModalInjection.unstable_Modal ?? Modal;
const ExportedModal: React.ComponentType<React.ElementConfig<typeof Modal>> =
ModalInjection.unstable_Modal ?? Modal;

module.exports = ExportedModal;
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function setRuntimeConfigProvider(
* The supplied `viewConfigProvider` may or may not be invoked and utilized,
* depending on how `setRuntimeConfigProvider` is configured.
*/
export function get<Config>(
export function get<Config: {...}>(
name: string,
viewConfigProvider: () => PartialViewConfig,
): HostComponent<Config> {
Expand Down Expand Up @@ -121,10 +121,10 @@ export function get<Config>(
* that the return value of this is not `HostComponent` because the returned
* component instance is not guaranteed to have native methods.
*/
export function getWithFallback_DEPRECATED<Config>(
export function getWithFallback_DEPRECATED<Config: {...}>(
name: string,
viewConfigProvider: () => PartialViewConfig,
): React.AbstractComponent<Config> {
): React.ComponentType<Config> {
if (getRuntimeConfig == null) {
// `getRuntimeConfig == null` when static view configs are disabled
// If `setRuntimeConfigProvider` is not configured, use native reflection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const PERMISSIONS = Object.freeze({
*/

class PermissionsAndroid {
PERMISSIONS: {|
PERMISSIONS: $ReadOnly<{|
ACCEPT_HANDOVER: string,
ACCESS_BACKGROUND_LOCATION: string,
ACCESS_COARSE_LOCATION: string,
Expand Down Expand Up @@ -132,12 +132,12 @@ class PermissionsAndroid {
WRITE_CALL_LOG: string,
WRITE_CONTACTS: string,
WRITE_EXTERNAL_STORAGE: string,
|} = PERMISSIONS;
RESULTS: {|
|}> = PERMISSIONS;
RESULTS: $ReadOnly<{|
DENIED: 'denied',
GRANTED: 'granted',
NEVER_ASK_AGAIN: 'never_ask_again',
|} = PERMISSION_REQUEST_RESULT;
|}> = PERMISSION_REQUEST_RESULT;

/**
* DEPRECATED - use check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type Props = $ReadOnly<{|
internal_excludeInspector?: boolean,
|}>;

const AppContainer: React.AbstractComponent<Props> = __DEV__
const AppContainer: component(...Props) = __DEV__
? require('./AppContainer-dev').default
: require('./AppContainer-prod').default;

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/ReactNative/DisplayMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export opaque type DisplayModeType = number;

/** DisplayMode should be in sync with the method displayModeToInt from
* react/renderer/uimanager/primitives.h. */
const DisplayMode: {[string]: DisplayModeType} = Object.freeze({
const DisplayMode: {+[string]: DisplayModeType} = Object.freeze({
VISIBLE: 1,
SUSPENDED: 2,
HIDDEN: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export function isProfilingRenderer(): boolean {
}

export function isChildPublicInstance(
parentInstance: ReactFabricHostComponent | HostComponent<mixed>,
childInstance: ReactFabricHostComponent | HostComponent<mixed>,
parentInstance: ReactFabricHostComponent | HostComponent<empty>,
childInstance: ReactFabricHostComponent | HostComponent<empty>,
): boolean {
return require('../Renderer/shims/ReactNative').isChildPublicInstance(
parentInstance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
* @format
*/

import type {AbstractComponent} from 'react';

import * as React from 'react';

type NoopComponent = AbstractComponent<{children: React.Node}>;
type NoopComponent = component(children: React.Node);

const cache: Map<
string, // displayName
Expand Down
Loading

0 comments on commit 848e4b2

Please sign in to comment.