Files
Nick Gerleman 5d26ceaa23 Fixup TS Organization (#35169)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35169

This reorganizes typing structure a bit.

`Utilities.d.ts` was originally added for utilitiy types but I ended up leaving it a grab bag of types that didn't belong to any individual bit of code. Out of what is in it right now, `Insets` was actually public, and seems to have been imported.

We also run into files around the renderer which are [currently overwritten](https://github.com/facebook/react-native/commits/e286da25fc83324363486eb668806aca179f74b3/Libraries/Renderer/implementations/ReactNativeRenderer.d.ts) by the React sync script.

Finally, all of the top-level imports of `Utilities` were auto-generated by VS Code, but fail in real apps. I think this is because our tsconfig sets a `baseUrl` to allow resolution from the types folder, so the tooling in the RN repo will use that, but it breaks in real apps that don't have that mapping.

This splits all these up into a couple separate directories that are hopefully easier to reason about, and removes `Omit` which has been a builtin type for quite some time (we were actually already using built-in `Omit`).

Changelog:
[General][Fixed] - Fixup TS Organization

Reviewed By: cipolleschi

Differential Revision: D40932319

fbshipit-source-id: 0b6e3e3eda603885b4dc01dcb9f5233aa546d128
2022-11-02 14:58:37 -07:00

116 lines
3.1 KiB
TypeScript

/**
* 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
*/
import type * as React from 'react';
import {Constructor} from '../../../types/private/Utilities';
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
import {ColorValue, StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {ViewProps} from '../View/ViewPropTypes';
import {NativeSyntheticEvent, TargetedEvent} from '../../Types/CoreEventTypes';
export interface SwitchPropsIOS extends ViewProps {
/**
* Background color when the switch is turned on.
*
* @deprecated use trackColor instead
*/
onTintColor?: ColorValue | undefined;
/**
* Color of the foreground switch grip.
*
* @deprecated use thumbColor instead
*/
thumbTintColor?: ColorValue | undefined;
/**
* Background color when the switch is turned off.
*
* @deprecated use trackColor instead
*/
tintColor?: ColorValue | undefined;
}
export interface SwitchChangeEventData extends TargetedEvent {
value: boolean;
}
export interface SwitchChangeEvent
extends NativeSyntheticEvent<SwitchChangeEventData> {}
export interface SwitchProps extends SwitchPropsIOS {
/**
* Color of the foreground switch grip.
*/
thumbColor?: ColorValue | undefined;
/**
* Custom colors for the switch track
*
* Color when false and color when true
*/
trackColor?:
| {
false?: ColorValue | null | undefined;
true?: ColorValue | null | undefined;
}
| undefined;
/**
* If true the user won't be able to toggle the switch.
* Default value is false.
*/
disabled?: boolean | undefined;
/**
* Invoked with the change event as an argument when the value changes.
*/
onChange?:
| ((event: SwitchChangeEvent) => Promise<void> | void)
| null
| undefined;
/**
* Invoked with the new value when the value changes.
*/
onValueChange?: ((value: boolean) => Promise<void> | void) | null | undefined;
/**
* Used to locate this view in end-to-end tests.
*/
testID?: string | undefined;
/**
* The value of the switch. If true the switch will be turned on.
* Default value is false.
*/
value?: boolean | undefined;
/**
* On iOS, custom color for the background.
* Can be seen when the switch value is false or when the switch is disabled.
*/
ios_backgroundColor?: ColorValue | undefined;
style?: StyleProp<ViewStyle> | undefined;
}
/**
* Renders a boolean input.
*
* This is a controlled component that requires an `onValueChange` callback that
* updates the `value` prop in order for the component to reflect user actions.
* If the `value` prop is not updated, the component will continue to render
* the supplied `value` prop instead of the expected result of any user actions.
*/
declare class SwitchComponent extends React.Component<SwitchProps> {}
declare const SwitchBase: Constructor<NativeMethods> & typeof SwitchComponent;
export class Switch extends SwitchBase {}