Skip to content

Commit

Permalink
Add a couple of mac specific exports to the TS exports (#1825)
Browse files Browse the repository at this point in the history
* Add a couple of mac specific exports to the TS exports

* format

* Add macos view/textinput/image props to TS exports

* formatting

* Update comments to use lowercase macOS, and add a couple more tags

* lint fix
  • Loading branch information
acoates-ms authored May 31, 2023
1 parent 538d6a0 commit 29d3981
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type AccessibilityChangeEventName =
| 'change' // deprecated, maps to screenReaderChanged
| 'boldTextChanged' // iOS-only Event
| 'grayscaleChanged' // iOS-only Event
| 'highContrastChanged' // [macOS]
| 'invertColorsChanged' // iOS-only Event
| 'reduceMotionChanged'
| 'screenReaderChanged'
Expand Down Expand Up @@ -57,6 +58,14 @@ export interface AccessibilityInfoStatic {
*/
isGrayscaleEnabled: () => Promise<boolean>;

/**
*
* @returns Query whether high contract is currently enabled.
*
* @platform macos
*/
isHighContrastEnabled: () => Promise<boolean>;

/**
* Query whether invert colors is currently enabled.
*
Expand Down
107 changes: 107 additions & 0 deletions Libraries/Components/TextInput/TextInput.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,113 @@ export interface TextInputIOSProps {
scrollEnabled?: boolean | undefined;
}

// [macOS
export type SettingChangeEvent = NativeSyntheticEvent<{
enabled: boolean;
}>;

export type PasteEvent = NativeSyntheticEvent<{
dataTransfer: {
files: {
height: number;
size: number;
type: string;
uri: string;
width: number;
}[];
items: {
kind: string;
type: string;
}[];
types: string[];
};
}>;

export type SubmitKeyEvent = {
key: string;
altKey?: boolean | undefined;
ctrlKey?: boolean | undefined;
metaKey?: boolean | undefined;
shiftKey?: boolean | undefined;
functionKey?: boolean | undefined;
};

export type PasteType = 'fileUrl' | 'image' | 'string';
export type PastedTypesType = PasteType | PasteType[];

/**
* macOS Specific properties for TextInput
*/
export interface TextInputMacOSProps {
/**
* If `true`, clears the text field synchronously before `onSubmitEditing` is emitted.
*/
clearTextOnSubmit?: boolean | undefined;

/**
* If `false`, disables grammar-check.
*/
grammarCheck?: boolean | undefined;

/**
* If `true`, hide vertical scrollbar on the underlying multiline scrollview
* The default value is `false`.
*/
hideVerticalScrollIndicator?: boolean | undefined;

/**
* Fired when a supported element is pasted
*/
onPaste?: (event: PasteEvent) => void | undefined;

/**
* Callback that is called when the text input's autoCorrect setting changes.
* This will be called with
* `{ nativeEvent: { enabled } }`.
* Does only work with 'multiline={true}'.
*/
onAutoCorrectChange?: (e: SettingChangeEvent) => void | undefined;

/**
* Callback that is called when the text input's spellCheck setting changes.
* This will be called with
* `{ nativeEvent: { enabled } }`.
* Does only work with 'multiline={true}'.
*/
onSpellCheckChange?: (e: SettingChangeEvent) => void | undefined;

/**
* Callback that is called when the text input's grammarCheck setting changes.
* This will be called with
* `{ nativeEvent: { enabled } }`.
* Does only work with 'multiline={true}'.
*/
onGrammarCheckChange?: (e: SettingChangeEvent) => void | undefined;

/**
* Enables Paste support for certain types of pasted types
*
* Possible values for `pastedTypes` are:
*
* - `'fileUrl'`
* - `'image'`
* - `'string'`
*/
pastedTypes?: PastedTypesType | undefined;

/**
* Configures keys that can be used to submit editing for the TextInput. Defaults to 'Enter' key.
*/
submitKeyEvents?: SubmitKeyEvent[] | undefined;

/**
* Specifies the tooltip.
*/
tooltip?: string | undefined;
}

// macOS]

/**
* Android Specific properties for TextInput
* @see https://reactnative.dev/docs/textinput#props
Expand Down
26 changes: 25 additions & 1 deletion Libraries/Components/View/ViewPropTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {Insets} from '../../../types/public/Insets';
import {GestureResponderHandlers} from '../../../types/public/ReactNativeRenderer';
import {StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {LayoutChangeEvent, PointerEvents} from '../../Types/CoreEventTypes';
import {
KeyEvent,
LayoutChangeEvent,
MouseEvent,
PointerEvents,
} from '../../Types/CoreEventTypes';
import {Touchable} from '../Touchable/Touchable';
import {AccessibilityProps} from './ViewAccessibility';

Expand Down Expand Up @@ -163,12 +168,31 @@ export interface ViewPropsAndroid {
focusable?: boolean | undefined;
}

export type DraggedType = 'fileUrl';
export type DraggedTypesType = DraggedType | DraggedType[];

export interface ViewPropsMacOS {
acceptsFirstMouse?: boolean | undefined;
enableFocusRing?: boolean | undefined;
onMouseEnter?: ((event: MouseEvent) => void) | undefined;
onMouseLeave?: ((event: MouseEvent) => void) | undefined;
onDragEnter?: ((event: MouseEvent) => void) | undefined;
onDragLeave?: ((event: MouseEvent) => void) | undefined;
onDrop?: ((event: MouseEvent) => void) | undefined;
onKeyDown?: ((event: KeyEvent) => void) | undefined;
onKeyUp?: ((event: KeyEvent) => void) | undefined;
validKeysDown?: string[] | undefined;
validKeysUp?: string[] | undefined;
draggedTypes?: DraggedTypesType | undefined;
}

/**
* @see https://reactnative.dev/docs/view#props
*/
export interface ViewProps
extends ViewPropsAndroid,
ViewPropsIOS,
ViewPropsMacOS,
GestureResponderHandlers,
Touchable,
PointerEvents,
Expand Down
5 changes: 5 additions & 0 deletions Libraries/Image/Image.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ interface ImagePropsAndroid {
fadeDuration?: number | undefined;
}

interface ImagePropsMacOS {
tooltip?: string | undefined;
}

/**
* @see https://reactnative.dev/docs/image#source
*/
Expand Down Expand Up @@ -117,6 +121,7 @@ export interface ImageResolvedAssetSource {
export interface ImagePropsBase
extends ImagePropsIOS,
ImagePropsAndroid,
ImagePropsMacOS,
AccessibilityProps {
/**
* Used to reference react managed images from native code.
Expand Down
28 changes: 28 additions & 0 deletions Libraries/StyleSheet/PlatformColorValueTypesMacOS.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @format
*/

import {ColorValue, OpaqueColorValue} from './StyleSheet';

type DynamicColorMacOSTuple = {
light: ColorValue;
dark: ColorValue;
highContrastLight?: ColorValue;
highContrastDark?: ColorValue;
};

export function DynamicColorMacOS(
tuple: DynamicColorMacOSTuple,
): OpaqueColorValue;

type SystemEffectMacOS =
| 'none'
| 'pressed'
| 'deepPressed'
| 'disabled'
| 'rollover';

export function ColorWithSystemEffectMacOS(
color: ColorValue,
effect: SystemEffectMacOS,
): OpaqueColorValue;
22 changes: 22 additions & 0 deletions Libraries/Types/CoreEventTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,25 @@ export interface PointerEvents {
onPointerUp?: ((event: PointerEvent) => void) | undefined;
onPointerUpCapture?: ((event: PointerEvent) => void) | undefined;
}

// [macOS
export interface NativeKeyEvent {
// Modifier keys
capsLockKey: boolean;
shiftKey: boolean;
ctrlKey: boolean;
altKey: boolean;
metaKey: boolean;
numericPadKey: boolean;
helpKey: boolean;
functionKey: boolean;
// Key options
ArrowLeft: boolean;
ArrowRight: boolean;
ArrowUp: boolean;
ArrowDown: boolean;
key: string;
}

export interface KeyEvent extends NativeSyntheticEvent<NativeKeyEvent> {}
// macOS]
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export * from '../Libraries/ReactNative/requireNativeComponent';
export * from '../Libraries/Settings/Settings';
export * from '../Libraries/Share/Share';
export * from '../Libraries/StyleSheet/PlatformColorValueTypesIOS';
export * from '../Libraries/StyleSheet/PlatformColorValueTypesMacOS'; // [macOS]
export * from '../Libraries/StyleSheet/PlatformColorValueTypes';
export * from '../Libraries/StyleSheet/StyleSheet';
export * from '../Libraries/StyleSheet/StyleSheetTypes';
Expand Down

0 comments on commit 29d3981

Please sign in to comment.