-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss-wrapped-components.tsx
More file actions
237 lines (200 loc) · 6.05 KB
/
css-wrapped-components.tsx
File metadata and controls
237 lines (200 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import { useCssElement } from 'react-native-css';
import {
LegendListProps,
LegendList as OriginalLegendList,
} from '@legendapp/list';
import { Image as RNImage } from 'expo-image';
import React from 'react';
import {
FlatList as RNFlatList,
Pressable as RNPressable,
ScrollView as RNScrollView,
StyleSheet,
Text as RNText,
TextInput as RNTextInput,
TouchableHighlight as RNTouchableHighlight,
TouchableOpacity as RNTouchableOpacity,
View as RNView,
} from 'react-native';
import Animated from 'react-native-reanimated';
import { VideoViewProps, VideoView as ExpoVideoView } from 'expo-video';
import { SafeAreaView as RNSafeAreaView } from 'react-native-safe-area-context';
// @legendapp/list
export const LegendList = (
props: LegendListProps & { className?: string; ref?: any },
): any => {
return useCssElement(OriginalLegendList as any, props, {
className: 'style',
contentContainerClassName: 'contentContainerStyle',
indicatorClassName: 'indicatorStyle',
columnWrapperClassName: 'columnWrapperStyle',
});
};
LegendList.displayName = 'CSS(LegendList)';
// expo-image
const AnimatedExpoImage = Animated.createAnimatedComponent(RNImage);
export type ImageProps = React.ComponentProps<typeof Image>;
function CSSImage(props: React.ComponentProps<typeof AnimatedExpoImage>) {
// @ts-expect-error: Remap objectFit style to contentFit property
const { objectFit, objectPosition, ...style } =
StyleSheet.flatten(props.style) || {};
return (
<AnimatedExpoImage
contentFit={objectFit}
contentPosition={objectPosition}
{...props}
source={
typeof props.source === 'string' ? { uri: props.source } : props.source
}
// @ts-expect-error: Style is remapped above
style={style}
/>
);
}
export const Image = (
props: React.ComponentProps<typeof CSSImage> & {
className?: string;
},
) => {
return useCssElement(CSSImage as any, props, {
className: 'style',
});
};
Image.displayName = 'CSS(Image)'; // CSS-enabled Image
// expo-video
export const VideoView = (
props: VideoViewProps & { className: string; ref: any },
): any => {
return useCssElement(ExpoVideoView, props, { className: 'style' });
};
VideoView.displayName = 'CSS(VideoView)';
// react-native-safe-area-context
// SafeAreaView
export const SafeAreaView = (
props: React.ComponentProps<typeof RNSafeAreaView> & {
className?: string;
},
) => {
return useCssElement(RNSafeAreaView, props, { className: 'style' });
};
SafeAreaView.displayName = 'CSS(SafeAreaView)';
// react-native
// AnimatedScrollView
export const AnimatedScrollView = (
props: React.ComponentProps<typeof Animated.ScrollView> & {
className?: string;
contentClassName?: string;
contentContainerClassName?: string;
},
) => {
return useCssElement(Animated.ScrollView as any, props, {
className: 'style',
contentClassName: 'contentContainerStyle',
contentContainerClassName: 'contentContainerStyle',
});
};
AnimatedScrollView.displayName = 'CSS(AnimatedScrollView)'; // AnimatedText
// AnimatedText
export const AnimatedText = (
props: React.ComponentProps<typeof Animated.Text> & { className?: string },
) => {
return useCssElement(Animated.Text as any, props, { className: 'style' });
};
AnimatedText.displayName = 'CSS(AnimatedText)';
// AnimatedView
export const AnimatedView = (
props: React.ComponentProps<typeof Animated.View> & { className?: string },
) => {
return useCssElement(Animated.View as any, props, { className: 'style' });
};
AnimatedView.displayName = 'CSS(AnimatedView)';
// FlatList
export function FlatList<T>(
props: React.ComponentProps<typeof RNFlatList<T>> & {
className?: string;
contentContainerClassName?: string;
},
) {
const inputComponent = RNFlatList as any;
return useCssElement(inputComponent, props, {
className: 'style',
contentContainerClassName: 'contentContainerStyle',
});
}
FlatList.displayName = 'CSS(FlatList)';
// Pressable
export const Pressable = (
props: React.ComponentProps<typeof RNPressable> & { className?: string },
) => {
return useCssElement(RNPressable as any, props, { className: 'style' });
};
Pressable.displayName = 'CSS(Pressable)';
// ScrollView
export const ScrollView = (
props: React.ComponentProps<typeof RNScrollView> & {
className?: string;
contentContainerClassName?: string;
},
) => {
return useCssElement(RNScrollView as any, props, {
className: 'style',
contentContainerClassName: 'contentContainerStyle',
});
};
ScrollView.displayName = 'CSS(ScrollView)';
// Text
export const Text = (
props: React.ComponentProps<typeof RNText> & { className?: string },
) => {
return useCssElement(RNText, props, { className: 'style' });
};
Text.displayName = 'CSS(Text)';
// TextInput
export const TextInput = (
props: React.ComponentProps<typeof RNTextInput> & { className?: string },
) => {
return useCssElement(RNTextInput, props, { className: 'style' });
};
TextInput.displayName = 'CSS(TextInput)';
function XXTouchableHighlight(
props: React.ComponentProps<typeof RNTouchableHighlight>,
) {
const { underlayColor, ...style } =
(StyleSheet.flatten(props.style) as any) || {};
return (
<RNTouchableHighlight
underlayColor={underlayColor}
{...props}
style={style}
/>
);
}
export const TouchableHighlight = (
props: React.ComponentProps<typeof RNTouchableHighlight> & {
className?: string;
},
) => {
return useCssElement(XXTouchableHighlight as any, props, {
className: 'style',
});
};
TouchableHighlight.displayName = 'CSS(TouchableHighlight)';
// TouchableOpacity
export const TouchableOpacity = (
props: React.ComponentProps<typeof RNTouchableOpacity> & {
className?: string;
},
) => {
return useCssElement(RNTouchableOpacity as any, props, {
className: 'style',
});
};
TouchableOpacity.displayName = 'CSS(TouchableOpacity)';
// View
export type ViewProps = React.ComponentProps<typeof RNView> & {
className?: string;
};
export const View = (props: ViewProps) => {
return useCssElement(RNView, props, { className: 'style' });
};
View.displayName = 'CSS(View)';