Skip to content

Commit

Permalink
Add Pressable to the list of supported react-native components (emoti…
Browse files Browse the repository at this point in the history
…on-js#1958)

* add Pressable component to native types

* add new Pressable component to @emotion/native

* Remove ReactNativeComponentNames and simplify typings in the result

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
sanpoChew and Andarist authored Aug 9, 2020
1 parent fa273c0 commit 5695f76
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 54 deletions.
1 change: 1 addition & 0 deletions packages/native/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const components = [
'NavigatorIOS',
'Picker',
'PickerIOS',
'Pressable',
'ProgressBarAndroid',
'ProgressViewIOS',
'RecyclerViewBackedScrollView',
Expand Down
45 changes: 0 additions & 45 deletions packages/native/types/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,6 @@ type ReactNative = typeof RN

export type ReactNativeStyle = RN.ViewStyle | RN.TextStyle | RN.ImageStyle

export type ReactNativeComponentNames =
| 'ActivityIndicator'
| 'Button'
| 'DatePickerIOS'
| 'DrawerLayoutAndroid'
| 'FlatList'
| 'Image'
| 'ImageBackground'
| 'KeyboardAvoidingView'
| 'ListView'
| 'Modal'
| 'NavigatorIOS'
| 'Picker'
| 'PickerIOS'
| 'ProgressBarAndroid'
| 'ProgressViewIOS'
| 'RecyclerViewBackedScrollView'
| 'RefreshControl'
| 'SafeAreaView'
| 'ScrollView'
| 'SectionList'
| 'SegmentedControlIOS'
| 'Slider'
| 'SnapshotViewIOS'
| 'StatusBar'
| 'SwipeableListView'
| 'Switch'
| 'SwitchIOS'
| 'TabBarIOS'
| 'Text'
| 'TextInput'
| 'ToolbarAndroid'
| 'TouchableHighlight'
| 'TouchableNativeFeedback'
| 'TouchableOpacity'
| 'TouchableWithoutFeedback'
| 'View'
| 'ViewPagerAndroid'

export type ReactNativeComponents = Pick<ReactNative, ReactNativeComponentNames>

export type ReactNativeComponentProps<
ComponentName extends ReactNativeComponentNames
> = React.ComponentProps<ReactNativeComponents[ComponentName]>

export type ReactNativeStyleType<Props> = Props extends {
style?: RN.StyleProp<infer StyleType>
}
Expand Down
74 changes: 65 additions & 9 deletions packages/native/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Definitions by: Pat Sissons <https://github.com/patsissons>
// TypeScript Version: 3.4

import * as RN from 'react-native'
import { Theme } from '@emotion/react'

import {
Expand All @@ -9,9 +10,6 @@ import {
CSSInterpolation,
Interpolation,
ReactNativeStyle,
ReactNativeComponentNames,
ReactNativeComponentProps,
ReactNativeComponents,
ReactNativeStyleType
} from './base'

Expand All @@ -29,6 +27,8 @@ export {
StyledOptions
} from './base'

type ReactNative = typeof RN

export function css<StyleType extends ReactNativeStyle = ReactNativeStyle>(
template: TemplateStringsArray,
...args: Array<Interpolation>
Expand All @@ -40,13 +40,69 @@ export function css<StyleType extends ReactNativeStyle = ReactNativeStyle>(
...args: Array<CSSInterpolation>
): StyleType

export type StyledComponents = {
[ComponentName in ReactNativeComponentNames]: CreateStyledComponent<
ReactNativeComponentProps<ComponentName> & { theme?: Theme },
{},
{ ref?: React.Ref<InstanceType<ReactNativeComponents[ComponentName]>> },
ReactNativeStyleType<ReactNativeComponentProps<ComponentName>>
// those 2 are just copies of the `BaseCreateStyled` with supplied `C` type argument
type HostClassComponent<
C extends React.ComponentClass<any>
> = CreateStyledComponent<
React.ComponentProps<C> & { theme?: Theme },
{},
{ ref?: React.Ref<InstanceType<C>> },
ReactNativeStyleType<React.ComponentProps<C>>
>
type HostFunctionComponent<
C extends React.FunctionComponent<any>
> = CreateStyledComponent<
React.ComponentProps<C> & { theme?: Theme },
{},
{},
ReactNativeStyleType<React.ComponentProps<C>>
>

export interface StyledComponents {
ActivityIndicator: HostClassComponent<ReactNative['ActivityIndicator']>
Button: HostClassComponent<ReactNative['Button']>
DatePickerIOS: HostClassComponent<ReactNative['DatePickerIOS']>
DrawerLayoutAndroid: HostClassComponent<ReactNative['DrawerLayoutAndroid']>
FlatList: HostClassComponent<ReactNative['FlatList']>
Image: HostClassComponent<ReactNative['Image']>
ImageBackground: HostClassComponent<ReactNative['ImageBackground']>
KeyboardAvoidingView: HostClassComponent<ReactNative['KeyboardAvoidingView']>
ListView: HostClassComponent<ReactNative['ListView']>
Modal: HostClassComponent<ReactNative['Modal']>
NavigatorIOS: HostClassComponent<ReactNative['NavigatorIOS']>
Picker: HostClassComponent<ReactNative['Picker']>
PickerIOS: HostClassComponent<ReactNative['PickerIOS']>
Pressable: HostFunctionComponent<ReactNative['Pressable']>
ProgressBarAndroid: HostClassComponent<ReactNative['ProgressBarAndroid']>
ProgressViewIOS: HostClassComponent<ReactNative['ProgressViewIOS']>
RecyclerViewBackedScrollView: HostClassComponent<
ReactNative['RecyclerViewBackedScrollView']
>
RefreshControl: HostClassComponent<ReactNative['RefreshControl']>
SafeAreaView: HostClassComponent<ReactNative['SafeAreaView']>
ScrollView: HostClassComponent<ReactNative['ScrollView']>
SectionList: HostClassComponent<ReactNative['SectionList']>
SegmentedControlIOS: HostClassComponent<ReactNative['SegmentedControlIOS']>
Slider: HostClassComponent<ReactNative['Slider']>
SnapshotViewIOS: HostClassComponent<ReactNative['SnapshotViewIOS']>
StatusBar: HostClassComponent<ReactNative['StatusBar']>
SwipeableListView: HostClassComponent<ReactNative['SwipeableListView']>
Switch: HostClassComponent<ReactNative['Switch']>
SwitchIOS: HostClassComponent<ReactNative['SwitchIOS']>
TabBarIOS: HostClassComponent<ReactNative['TabBarIOS']>
Text: HostClassComponent<ReactNative['Text']>
TextInput: HostClassComponent<ReactNative['TextInput']>
ToolbarAndroid: HostClassComponent<ReactNative['ToolbarAndroid']>
TouchableHighlight: HostClassComponent<ReactNative['TouchableHighlight']>
TouchableNativeFeedback: HostClassComponent<
ReactNative['TouchableNativeFeedback']
>
TouchableOpacity: HostClassComponent<ReactNative['TouchableOpacity']>
TouchableWithoutFeedback: HostClassComponent<
ReactNative['TouchableWithoutFeedback']
>
View: HostClassComponent<ReactNative['View']>
ViewPagerAndroid: HostClassComponent<ReactNative['ViewPagerAndroid']>
}

export interface CreateStyled extends BaseCreateStyled, StyledComponents {}
Expand Down

0 comments on commit 5695f76

Please sign in to comment.