Skip to main content

View props

Boolean prop

src/NativeMyAwesomeModule.ts
import type { HostComponent, ViewProps } from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

// ...

export interface MyAwesomeViewProps extends ViewProps {
enabled: boolean
checked?: boolean
}

export default codegenNativeComponent<MyAwesomeViewProps>('MyAwesomeView') as HostComponent<MyAwesomeViewProps>;

Number prop

src/MyAwesomeViewNativeComponent.ts
import type { HostComponent, ViewProps } from 'react-native';
import type {
Double,
Float,
Int32,
} from 'react-native/Libraries/Types/CodegenTypes';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

// ...

export interface MyAwesomeViewProps extends ViewProps {
precision: Double
optionalPrecision?: Double
price: Float
discount?: Float
count: Int32
optionalCount?: Int32
}

export default codegenNativeComponent<MyAwesomeViewProps>('MyAwesomeView') as HostComponent<MyAwesomeViewProps>;

String prop

src/NativeMyAwesomeModule.ts
import type { HostComponent, ViewProps } from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

// ...

export interface MyAwesomeViewProps extends ViewProps {
name: string
label?: string
}

export default codegenNativeComponent<MyAwesomeViewProps>('MyAwesomeView') as HostComponent<MyAwesomeViewProps>;

Array prop

src/NativeMyAwesomeModule.ts
import type { HostComponent, ViewProps } from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

// ...

export interface MyAwesomeViewProps extends ViewProps {
data: ReadonlyArray<number>
optionalData?: ReadonlyArray<Readonly<{ title: string, description: string }>>
}

export default codegenNativeComponent<MyAwesomeViewProps>('MyAwesomeView') as HostComponent<MyAwesomeViewProps>;

Object prop

src/NativeMyAwesomeModule.ts
import type { HostComponent, ViewProps } from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

// ...

export interface MyAwesomeViewProps extends ViewProps {
enabled: boolean
checked?: boolean
}

export default codegenNativeComponent<MyAwesomeViewProps>('MyAwesomeView') as HostComponent<MyAwesomeViewProps>;

Color prop

src/NativeMyAwesomeModule.ts
import type { ColorValue, HostComponent, ViewProps } from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

// ...

export interface MyAwesomeViewProps extends ViewProps {
tintColor: ColorValue
optionalColor?: ColorValue
}

export default codegenNativeComponent<MyAwesomeViewProps>('MyAwesomeView') as HostComponent<MyAwesomeViewProps>;

Event handler prop

src/NativeMyAwesomeModule.ts
import type { HostComponent, ViewProps } from 'react-native';
import type {
BubblingEventHandler,
DirectEventHandler,
} from 'react-native/Libraries/Types/CodegenTypes';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

// ...

export interface MyAwesomeViewProps extends ViewProps {
onAwesomeBubblingEvent?: BubblingEventHandler<Readonly<{ arg: string }>>
onAwesomeDirectEvent?: DirectEventHandler<Readonly<{ arg: string }>>
}

export default codegenNativeComponent<MyAwesomeViewProps>('MyAwesomeView') as HostComponent<MyAwesomeViewProps>;

Prop with default value

src/NativeMyAwesomeModule.ts
import type { HostComponent, ViewProps } from 'react-native';
import type { WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

// ...

export interface MyAwesomeViewProps extends ViewProps {
interval?: WithDefault<'slow' | 'normal' | 'fast', 'normal'>
}

export default codegenNativeComponent<MyAwesomeViewProps>('MyAwesomeView') as HostComponent<MyAwesomeViewProps>;