cpk-ui 0.5.5 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/README.md +80 -147
  2. package/components/modals/AlertDialog/AlertDialog.d.ts.map +1 -1
  3. package/components/modals/AlertDialog/AlertDialog.js +14 -7
  4. package/components/modals/Snackbar/Snackbar.d.ts.map +1 -1
  5. package/components/modals/Snackbar/Snackbar.js +20 -17
  6. package/components/uis/Accordion/AccordionItem.d.ts.map +1 -1
  7. package/components/uis/Accordion/AccordionItem.js +41 -17
  8. package/components/uis/Button/Button.d.ts.map +1 -1
  9. package/components/uis/Button/Button.js +10 -10
  10. package/components/uis/Card/Card.d.ts +2 -1
  11. package/components/uis/Card/Card.d.ts.map +1 -1
  12. package/components/uis/Card/Card.js +12 -3
  13. package/components/uis/Checkbox/Checkbox.d.ts.map +1 -1
  14. package/components/uis/Checkbox/Checkbox.js +1 -1
  15. package/components/uis/CustomPressable/CustomPressable.d.ts.map +1 -1
  16. package/components/uis/CustomPressable/CustomPressable.js +6 -6
  17. package/components/uis/EditText/EditText.d.ts.map +1 -1
  18. package/components/uis/EditText/EditText.js +17 -12
  19. package/components/uis/Fab/Fab.d.ts +2 -2
  20. package/components/uis/Fab/Fab.d.ts.map +1 -1
  21. package/components/uis/Fab/Fab.js +22 -4
  22. package/components/uis/Icon/Icon.d.ts.map +1 -1
  23. package/components/uis/Icon/Icon.js +6 -3
  24. package/components/uis/IconButton/IconButton.d.ts.map +1 -1
  25. package/components/uis/IconButton/IconButton.js +43 -41
  26. package/components/uis/LoadingIndicator/LoadingIndicator.d.ts +2 -1
  27. package/components/uis/LoadingIndicator/LoadingIndicator.d.ts.map +1 -1
  28. package/components/uis/LoadingIndicator/LoadingIndicator.js +4 -4
  29. package/components/uis/RadioGroup/RadioButton.d.ts.map +1 -1
  30. package/components/uis/RadioGroup/RadioButton.js +1 -1
  31. package/components/uis/RadioGroup/RadioGroup.d.ts.map +1 -1
  32. package/components/uis/RadioGroup/RadioGroup.js +16 -3
  33. package/components/uis/Rating/Rating.d.ts.map +1 -1
  34. package/components/uis/Rating/Rating.js +23 -19
  35. package/components/uis/SegmentedControl/SegmentedControl.d.ts.map +1 -1
  36. package/components/uis/SegmentedControl/SegmentedControl.js +1 -1
  37. package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts +2 -2
  38. package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts.map +1 -1
  39. package/components/uis/StatusbarBrightness/StatusBarBrightness.js +1 -1
  40. package/components/uis/SwitchToggle/SwitchToggle.d.ts.map +1 -1
  41. package/components/uis/SwitchToggle/SwitchToggle.js +1 -1
  42. package/hooks/useHoverState.d.ts +8 -0
  43. package/hooks/useHoverState.d.ts.map +1 -0
  44. package/hooks/useHoverState.js +16 -0
  45. package/package.json +18 -6
  46. package/providers/ThemeProvider.d.ts.map +1 -1
  47. package/providers/ThemeProvider.js +0 -1
  48. package/providers/index.d.ts.map +1 -1
  49. package/providers/index.js +3 -2
  50. package/components/uis/Icon/selection.json +0 -1
  51. package/src/components/common/ErrorBoundary/ErrorBoundary.tsx +0 -75
  52. package/src/components/modals/AlertDialog/AlertDialog.stories.tsx +0 -216
  53. package/src/components/modals/AlertDialog/AlertDialog.test.tsx +0 -251
  54. package/src/components/modals/AlertDialog/AlertDialog.tsx +0 -356
  55. package/src/components/modals/Snackbar/Snackbar.stories.tsx +0 -182
  56. package/src/components/modals/Snackbar/Snackbar.test.tsx +0 -319
  57. package/src/components/modals/Snackbar/Snackbar.tsx +0 -260
  58. package/src/components/modals/Snackbar/const.ts +0 -4
  59. package/src/components/uis/Accordion/Accordion.stories.tsx +0 -167
  60. package/src/components/uis/Accordion/Accordion.test.tsx +0 -272
  61. package/src/components/uis/Accordion/Accordion.tsx +0 -109
  62. package/src/components/uis/Accordion/AccordionItem.tsx +0 -306
  63. package/src/components/uis/Button/Button.stories.tsx +0 -218
  64. package/src/components/uis/Button/Button.test.tsx +0 -694
  65. package/src/components/uis/Button/Button.tsx +0 -440
  66. package/src/components/uis/Card/Card.test.tsx +0 -146
  67. package/src/components/uis/Card/Card.tsx +0 -102
  68. package/src/components/uis/Checkbox/Checkbox.stories.tsx +0 -216
  69. package/src/components/uis/Checkbox/Checkbox.test.tsx +0 -267
  70. package/src/components/uis/Checkbox/Checkbox.tsx +0 -225
  71. package/src/components/uis/CustomPressable/CustomPressable.tsx +0 -48
  72. package/src/components/uis/EditText/EditText.stories.tsx +0 -124
  73. package/src/components/uis/EditText/EditText.test.tsx +0 -477
  74. package/src/components/uis/EditText/EditText.tsx +0 -593
  75. package/src/components/uis/Fab/Fab.stories.tsx +0 -133
  76. package/src/components/uis/Fab/Fab.test.tsx +0 -110
  77. package/src/components/uis/Fab/Fab.tsx +0 -168
  78. package/src/components/uis/Hr/Hr.test.tsx +0 -26
  79. package/src/components/uis/Hr/Hr.tsx +0 -19
  80. package/src/components/uis/Icon/Icon.stories.tsx +0 -98
  81. package/src/components/uis/Icon/Icon.test.tsx +0 -49
  82. package/src/components/uis/Icon/Icon.tsx +0 -3819
  83. package/src/components/uis/IconButton/IconButton.test.tsx +0 -204
  84. package/src/components/uis/IconButton/IconButton.tsx +0 -279
  85. package/src/components/uis/LoadingIndicator/LoadingIndicator.tsx +0 -126
  86. package/src/components/uis/LoadingIndicator/LodingIndicator.stories.tsx +0 -81
  87. package/src/components/uis/PinchZoom/PinchZoom.stories.tsx +0 -266
  88. package/src/components/uis/PinchZoom/PinchZoom.test.tsx +0 -113
  89. package/src/components/uis/PinchZoom/PinchZoom.tsx +0 -424
  90. package/src/components/uis/RadioGroup/RadioButton.tsx +0 -193
  91. package/src/components/uis/RadioGroup/RadioGroup.stories.tsx +0 -188
  92. package/src/components/uis/RadioGroup/RadioGroup.test.tsx +0 -354
  93. package/src/components/uis/RadioGroup/RadioGroup.tsx +0 -109
  94. package/src/components/uis/Rating/Rating.test.tsx +0 -98
  95. package/src/components/uis/Rating/Rating.tsx +0 -200
  96. package/src/components/uis/SegmentedControl/SegmentedControl.stories.tsx +0 -546
  97. package/src/components/uis/SegmentedControl/SegmentedControl.test.tsx +0 -274
  98. package/src/components/uis/SegmentedControl/SegmentedControl.tsx +0 -232
  99. package/src/components/uis/StatusbarBrightness/StatusBarBrightness.test.tsx +0 -41
  100. package/src/components/uis/StatusbarBrightness/StatusBarBrightness.tsx +0 -26
  101. package/src/components/uis/Styled/StyledComponents.tsx +0 -217
  102. package/src/components/uis/SwitchToggle/SwitchToggle.stories.tsx +0 -75
  103. package/src/components/uis/SwitchToggle/SwitchToggle.test.tsx +0 -149
  104. package/src/components/uis/SwitchToggle/SwitchToggle.tsx +0 -309
  105. package/src/components/uis/Typography/Typography.stories.tsx +0 -149
  106. package/src/components/uis/Typography/Typography.test.tsx +0 -58
  107. package/src/components/uis/Typography/Typography.tsx +0 -386
  108. package/src/hooks/index.ts +0 -2
  109. package/src/hooks/useAnimations.ts +0 -71
  110. package/src/hooks/useDebouncedColorScheme.tsx +0 -30
  111. package/src/hooks/useOptimizedStyles.ts +0 -22
  112. package/src/hooks/usePerformance.ts +0 -93
  113. package/src/index.tsx +0 -38
  114. package/src/providers/ThemeProvider.tsx +0 -177
  115. package/src/providers/index.tsx +0 -130
  116. package/src/test/testUtils.tsx +0 -101
  117. package/src/types/common.ts +0 -77
  118. package/src/types/index.ts +0 -1
  119. package/src/types/kstyled.d.ts +0 -6
  120. package/src/utils/accessibility.ts +0 -110
  121. package/src/utils/colors.ts +0 -151
  122. package/src/utils/createCtx.tsx +0 -26
  123. package/src/utils/guards.ts +0 -93
  124. package/src/utils/index.ts +0 -2
  125. package/src/utils/performanceTest.ts +0 -174
  126. package/src/utils/platform.ts +0 -69
  127. package/src/utils/theme.ts +0 -38
  128. package/test/testUtils.d.ts +0 -113
  129. package/test/testUtils.d.ts.map +0 -1
  130. package/test/testUtils.js +0 -65
@@ -1,386 +0,0 @@
1
- import React, {ReactNode, useMemo} from 'react';
2
- import {StyleProp, Text, TextInput, Platform, StyleSheet} from 'react-native';
3
- import {CpkTheme, isEmptyObject} from '../../../utils/theme';
4
- import {light} from '../../../utils/colors';
5
- import {type TextStyle} from 'react-native';
6
- import {styled, css} from 'kstyled';
7
-
8
- type FontFamilyOptions = {
9
- normal: string;
10
- thin?: string;
11
- bold?: string;
12
- };
13
-
14
- type FontFamilyConfig = {
15
- heading?: FontFamilyOptions;
16
- body?: FontFamilyOptions;
17
- };
18
-
19
- const createBaseText = (
20
- colorResolver: (theme: CpkTheme) => string,
21
- fallbackColor: string,
22
- isHeading: boolean,
23
- ) => styled(Text)<{theme?: CpkTheme; $fontWeight?: 'normal' | 'bold' | 'thin'}>`
24
- font-family: ${({$fontWeight}) => {
25
- const fontFamilies = getFontFamilies(isHeading);
26
- const {normal, thin = normal, bold = normal} = fontFamilies;
27
- switch ($fontWeight) {
28
- case 'bold':
29
- return bold;
30
- case 'thin':
31
- return thin;
32
- default:
33
- return normal;
34
- }
35
- }};
36
- color: ${({theme}) => {
37
- if (!theme || isEmptyObject(theme)) {
38
- return fallbackColor;
39
- }
40
- return colorResolver(theme);
41
- }};
42
- `;
43
-
44
- type TextComponentType = ReturnType<typeof createBaseText>;
45
-
46
- const createTextComponent = ({
47
- BaseText,
48
- fontSize,
49
- lineHeight,
50
- fontWeight,
51
- isHeading,
52
- }: {
53
- BaseText: TextComponentType;
54
- fontSize: number;
55
- lineHeight: number;
56
- fontWeight?: 'normal' | 'bold' | 'thin';
57
- isHeading: boolean;
58
- }) =>
59
- React.memo(({
60
- style,
61
- children,
62
- ...props
63
- }: {
64
- style?: StyleProp<TextStyle>;
65
- children?: ReactNode;
66
- }) => {
67
- const fontFamilies = getFontFamilies(isHeading);
68
- const isCustomFont = Platform?.OS === 'android' && fontFamilies.normal !== 'Pretendard';
69
-
70
- // On Android, remove fontWeight when custom font is applied
71
- const effectiveFontWeight = isCustomFont ? undefined : fontWeight;
72
-
73
- // Memoize style calculation
74
- const textStyle = useMemo(() => [
75
- css`
76
- font-size: ${fontSize}px;
77
- line-height: ${lineHeight}px;
78
- ${effectiveFontWeight ? `font-weight: ${effectiveFontWeight};` : ''}
79
- `,
80
- {includeFontPadding: false},
81
- style,
82
- ], [style, effectiveFontWeight]);
83
-
84
- return (
85
- <BaseText
86
- {...props}
87
- $fontWeight={effectiveFontWeight}
88
- style={textStyle}
89
- >
90
- {children}
91
- </BaseText>
92
- );
93
- }) as unknown as TextComponentType;
94
-
95
- const StandardHeadingBaseText = createBaseText((theme) => theme.text.basic, 'gray', true);
96
- const StandardBodyBaseText = createBaseText((theme) => theme.text.basic, 'gray', false);
97
- const InvertedHeadingBaseText = createBaseText(
98
- (theme) => theme.text.contrast,
99
- light.text.contrast,
100
- true,
101
- );
102
- const InvertedBodyBaseText = createBaseText(
103
- (theme) => theme.text.contrast,
104
- light.text.contrast,
105
- false,
106
- );
107
-
108
- const Title = createTextComponent({
109
- BaseText: StandardHeadingBaseText,
110
- fontSize: 36,
111
- lineHeight: 50.4,
112
- fontWeight: 'bold',
113
- isHeading: true,
114
- });
115
-
116
- const Heading1 = createTextComponent({
117
- BaseText: StandardHeadingBaseText,
118
- fontSize: 28,
119
- lineHeight: 39.2,
120
- fontWeight: 'bold',
121
- isHeading: true,
122
- });
123
-
124
- const Heading2 = createTextComponent({
125
- BaseText: StandardHeadingBaseText,
126
- fontSize: 26,
127
- lineHeight: 36.4,
128
- fontWeight: 'bold',
129
- isHeading: true,
130
- });
131
-
132
- const Heading3 = createTextComponent({
133
- BaseText: StandardHeadingBaseText,
134
- fontSize: 24,
135
- lineHeight: 33.6,
136
- fontWeight: 'bold',
137
- isHeading: true,
138
- });
139
-
140
- const Heading4 = createTextComponent({
141
- BaseText: StandardHeadingBaseText,
142
- fontSize: 22,
143
- lineHeight: 30.8,
144
- fontWeight: 'bold',
145
- isHeading: true,
146
- });
147
-
148
- const Heading5 = createTextComponent({
149
- BaseText: StandardHeadingBaseText,
150
- fontSize: 20,
151
- lineHeight: 28,
152
- fontWeight: 'bold',
153
- isHeading: true,
154
- });
155
-
156
- const Body1 = createTextComponent({
157
- BaseText: StandardBodyBaseText,
158
- fontSize: 18,
159
- lineHeight: 25.2,
160
- isHeading: false,
161
- });
162
-
163
- const Body2 = createTextComponent({
164
- BaseText: StandardBodyBaseText,
165
- fontSize: 16,
166
- lineHeight: 22.4,
167
- isHeading: false,
168
- });
169
-
170
- const Body3 = createTextComponent({
171
- BaseText: StandardBodyBaseText,
172
- fontSize: 14,
173
- lineHeight: 19.6,
174
- isHeading: false,
175
- });
176
-
177
- const Body4 = createTextComponent({
178
- BaseText: StandardBodyBaseText,
179
- fontSize: 12,
180
- lineHeight: 16.4,
181
- isHeading: false,
182
- });
183
-
184
- const InvertedTitle = createTextComponent({
185
- BaseText: InvertedHeadingBaseText,
186
- fontSize: 36,
187
- lineHeight: 50.4,
188
- fontWeight: 'bold',
189
- isHeading: true,
190
- });
191
-
192
- const InvertedHeading1 = createTextComponent({
193
- BaseText: InvertedHeadingBaseText,
194
- fontSize: 28,
195
- lineHeight: 39.2,
196
- fontWeight: 'bold',
197
- isHeading: true,
198
- });
199
-
200
- const InvertedHeading2 = createTextComponent({
201
- BaseText: InvertedHeadingBaseText,
202
- fontSize: 26,
203
- lineHeight: 36.4,
204
- fontWeight: 'bold',
205
- isHeading: true,
206
- });
207
-
208
- const InvertedHeading3 = createTextComponent({
209
- BaseText: InvertedHeadingBaseText,
210
- fontSize: 24,
211
- lineHeight: 33.6,
212
- fontWeight: 'bold',
213
- isHeading: true,
214
- });
215
-
216
- const InvertedHeading4 = createTextComponent({
217
- BaseText: InvertedHeadingBaseText,
218
- fontSize: 22,
219
- lineHeight: 30.8,
220
- fontWeight: 'bold',
221
- isHeading: true,
222
- });
223
-
224
- const InvertedHeading5 = createTextComponent({
225
- BaseText: InvertedHeadingBaseText,
226
- fontSize: 20,
227
- lineHeight: 28,
228
- fontWeight: 'bold',
229
- isHeading: true,
230
- });
231
-
232
- const InvertedBody1 = createTextComponent({
233
- BaseText: InvertedBodyBaseText,
234
- fontSize: 18,
235
- lineHeight: 25.2,
236
- isHeading: false,
237
- });
238
-
239
- const InvertedBody2 = createTextComponent({
240
- BaseText: InvertedBodyBaseText,
241
- fontSize: 16,
242
- lineHeight: 22.4,
243
- isHeading: false,
244
- });
245
-
246
- const InvertedBody3 = createTextComponent({
247
- BaseText: InvertedBodyBaseText,
248
- fontSize: 14,
249
- lineHeight: 19.6,
250
- isHeading: false,
251
- });
252
-
253
- const InvertedBody4 = createTextComponent({
254
- BaseText: InvertedBodyBaseText,
255
- fontSize: 12,
256
- lineHeight: 16.4,
257
- isHeading: false,
258
- });
259
-
260
- export const Typography = {
261
- Title,
262
- Heading1,
263
- Heading2,
264
- Heading3,
265
- Heading4,
266
- Heading5,
267
- Body1,
268
- Body2,
269
- Body3,
270
- Body4,
271
- };
272
-
273
- export const TypographyInverted = {
274
- Title: InvertedTitle,
275
- Heading1: InvertedHeading1,
276
- Heading2: InvertedHeading2,
277
- Heading3: InvertedHeading3,
278
- Heading4: InvertedHeading4,
279
- Heading5: InvertedHeading5,
280
- Body1: InvertedBody1,
281
- Body2: InvertedBody2,
282
- Body3: InvertedBody3,
283
- Body4: InvertedBody4,
284
- };
285
-
286
- let currentFontFamilies: FontFamilyConfig = {
287
- heading: {
288
- normal: 'Pretendard',
289
- thin: 'Pretendard-Thin',
290
- bold: 'Pretendard-Bold',
291
- },
292
- body: {
293
- normal: 'Pretendard',
294
- thin: 'Pretendard-Thin',
295
- bold: 'Pretendard-Bold',
296
- },
297
- };
298
-
299
- export const setFontFamily = (fontFamilies: FontFamilyConfig): void => {
300
- if (fontFamilies.heading) {
301
- currentFontFamilies.heading = {
302
- ...currentFontFamilies.heading,
303
- ...fontFamilies.heading,
304
- };
305
- }
306
-
307
- if (fontFamilies.body) {
308
- currentFontFamilies.body = {
309
- ...currentFontFamilies.body,
310
- ...fontFamilies.body,
311
- };
312
- }
313
-
314
- // Memoize font family getter function
315
- const getFontFamily = (fontWeight: string | undefined, userFontFamily: string | undefined, isHeading: boolean): string => {
316
- // If user explicitly set fontFamily, use it (override)
317
- if (userFontFamily) {
318
- return userFontFamily;
319
- }
320
-
321
- const fontFamilies = isHeading ? currentFontFamilies.heading : currentFontFamilies.body;
322
- if (!fontFamilies) {
323
- // Fallback to default Pretendard if not configured
324
- return 'Pretendard';
325
- }
326
-
327
- const {normal, thin = normal, bold = normal} = fontFamilies;
328
-
329
- switch (fontWeight) {
330
- case 'bold':
331
- case '700':
332
- return bold;
333
- case '100':
334
- case '200':
335
- case '300':
336
- return thin;
337
- default:
338
- return normal;
339
- }
340
- };
341
-
342
- const applyFontFamily = (Component: typeof Text | typeof TextInput) => {
343
- // @ts-ignore
344
- const oldRender = Component.render;
345
-
346
- // @ts-ignore
347
- Component.render = function (...args: any) {
348
- const origin = oldRender.call(this, ...args);
349
-
350
- // Flatten styles using React Native's StyleSheet.flatten
351
- const flatStyle = StyleSheet.flatten(origin.props.style) ?? {};
352
-
353
- const fontWeight = flatStyle?.fontWeight;
354
- const userFontFamily = flatStyle?.fontFamily;
355
-
356
- // Default to body fonts for direct Text/TextInput usage
357
- // Heading fonts are applied via Typography components
358
- const isHeading = false;
359
-
360
- const updatedStyle = [
361
- {
362
- fontFamily: getFontFamily(fontWeight, userFontFamily, isHeading),
363
- includeFontPadding: false,
364
- },
365
- origin.props.style,
366
- ];
367
-
368
- return React.cloneElement(origin, {
369
- style: updatedStyle,
370
- });
371
- };
372
- };
373
-
374
- applyFontFamily(Text);
375
- applyFontFamily(TextInput);
376
- };
377
-
378
- // Memoize font families getter
379
- export const getFontFamilies = (isHeading: boolean): FontFamilyOptions => {
380
- const fontFamilies = isHeading ? currentFontFamilies.heading : currentFontFamilies.body;
381
- return fontFamilies || {
382
- normal: 'Pretendard',
383
- thin: 'Pretendard-Thin',
384
- bold: 'Pretendard-Bold',
385
- };
386
- };
@@ -1,2 +0,0 @@
1
- export * from './useOptimizedStyles';
2
- export * from './useAnimations';
@@ -1,71 +0,0 @@
1
- import {useRef, useEffect} from 'react';
2
- import {Animated, Easing} from 'react-native';
3
-
4
- export interface AnimationConfig {
5
- duration?: number;
6
- easing?: (value: number) => number;
7
- useNativeDriver?: boolean;
8
- }
9
-
10
- /**
11
- * Hook for optimized fade animations
12
- */
13
- export function useFadeAnimation(
14
- isVisible: boolean,
15
- config: AnimationConfig = {},
16
- ): Animated.Value {
17
- const fadeAnim = useRef(new Animated.Value(isVisible ? 1 : 0)).current;
18
-
19
- useEffect(() => {
20
- Animated.timing(fadeAnim, {
21
- toValue: isVisible ? 1 : 0,
22
- duration: config.duration ?? 200,
23
- easing: config.easing ?? Easing.ease,
24
- useNativeDriver: config.useNativeDriver ?? true,
25
- }).start();
26
- }, [isVisible, fadeAnim, config.duration, config.easing, config.useNativeDriver]);
27
-
28
- return fadeAnim;
29
- }
30
-
31
- /**
32
- * Hook for optimized slide animations
33
- */
34
- export function useSlideAnimation(
35
- isVisible: boolean,
36
- config: AnimationConfig & {direction?: 'up' | 'down' | 'left' | 'right'} = {},
37
- ): Animated.Value {
38
- const slideAnim = useRef(new Animated.Value(isVisible ? 0 : 1)).current;
39
-
40
- useEffect(() => {
41
- Animated.timing(slideAnim, {
42
- toValue: isVisible ? 0 : 1,
43
- duration: config.duration ?? 200,
44
- easing: config.easing ?? Easing.ease,
45
- useNativeDriver: config.useNativeDriver ?? true,
46
- }).start();
47
- }, [isVisible, slideAnim, config.duration, config.easing, config.useNativeDriver]);
48
-
49
- return slideAnim;
50
- }
51
-
52
- /**
53
- * Hook for optimized rotation animations
54
- */
55
- export function useRotateAnimation(
56
- isActive: boolean,
57
- config: AnimationConfig & {rotationDegrees?: number} = {},
58
- ): Animated.Value {
59
- const rotateAnim = useRef(new Animated.Value(0)).current;
60
-
61
- useEffect(() => {
62
- Animated.timing(rotateAnim, {
63
- toValue: isActive ? 1 : 0,
64
- duration: config.duration ?? 200,
65
- easing: config.easing ?? Easing.ease,
66
- useNativeDriver: config.useNativeDriver ?? true,
67
- }).start();
68
- }, [isActive, rotateAnim, config.duration, config.easing, config.useNativeDriver]);
69
-
70
- return rotateAnim;
71
- }
@@ -1,30 +0,0 @@
1
- import { useEffect, useState } from "react";
2
- import type { ColorSchemeName } from "react-native";
3
- import { useColorScheme } from "react-native";
4
-
5
- function useDebounce<T>(value: T, delay?: number): T {
6
- const [debouncedValue, setDebouncedValue] = useState<T>(value);
7
-
8
- useEffect(() => {
9
- const timer = setTimeout(() => setDebouncedValue(value), delay || 500);
10
-
11
- return () => {
12
- clearTimeout(timer);
13
- };
14
- }, [value, delay]);
15
-
16
- return debouncedValue;
17
- }
18
-
19
- /* ?
20
- * Strangely enough, when useColorScheme() returns from the background state, it first returns a different color value and later returns the original color value.
21
- * Due to this phenomenon, there's a momentary flickering effect on the screen.
22
- * Therefore, to prevent this, we use useDebounce to delay the return of the color value until after a certain amount of time has passed.
23
- */
24
- export function useDebouncedColorScheme(
25
- delay: number = 300
26
- ): "light" | "dark" | null | undefined {
27
- const colorScheme = useColorScheme();
28
-
29
- return useDebounce<ColorSchemeName>(colorScheme, delay);
30
- }
@@ -1,22 +0,0 @@
1
- import {useMemo} from 'react';
2
- import type {StyleProp, ViewStyle, TextStyle} from 'react-native';
3
-
4
- /**
5
- * Hook to optimize style objects and prevent unnecessary re-renders
6
- */
7
- export function useOptimizedStyles<T extends Record<string, StyleProp<ViewStyle | TextStyle>>>(
8
- styleFactory: () => T,
9
- dependencies: React.DependencyList,
10
- ): T {
11
- return useMemo(styleFactory, dependencies);
12
- }
13
-
14
- /**
15
- * Hook to memoize style arrays
16
- */
17
- export function useStyleArray<T extends StyleProp<ViewStyle | TextStyle>>(
18
- styles: T[],
19
- dependencies: React.DependencyList,
20
- ): T[] {
21
- return useMemo(() => styles, dependencies);
22
- }
@@ -1,93 +0,0 @@
1
- import {useEffect, useRef} from 'react';
2
-
3
- interface PerformanceMetrics {
4
- componentName: string;
5
- renderCount: number;
6
- lastRenderTime: number;
7
- averageRenderTime: number;
8
- slowRenders: number;
9
- }
10
-
11
- const SLOW_RENDER_THRESHOLD = 16; // 16ms for 60fps
12
-
13
- /**
14
- * Hook to monitor component render performance
15
- * Only active in development mode
16
- */
17
- export function usePerformanceMonitor(
18
- componentName: string,
19
- enabled: boolean = __DEV__,
20
- ): PerformanceMetrics | null {
21
- const metricsRef = useRef<PerformanceMetrics>({
22
- componentName,
23
- renderCount: 0,
24
- lastRenderTime: 0,
25
- averageRenderTime: 0,
26
- slowRenders: 0,
27
- });
28
-
29
- const startTimeRef = useRef<number>(0);
30
-
31
- useEffect(() => {
32
- if (!enabled) return;
33
-
34
- const endTime = performance.now();
35
- const renderTime = endTime - startTimeRef.current;
36
-
37
- const metrics = metricsRef.current;
38
- metrics.renderCount++;
39
- metrics.lastRenderTime = renderTime;
40
- metrics.averageRenderTime =
41
- (metrics.averageRenderTime * (metrics.renderCount - 1) + renderTime) /
42
- metrics.renderCount;
43
-
44
- if (renderTime > SLOW_RENDER_THRESHOLD) {
45
- metrics.slowRenders++;
46
- console.warn(
47
- `Slow render detected in ${componentName}: ${renderTime.toFixed(2)}ms`,
48
- );
49
- }
50
- });
51
-
52
- if (enabled) {
53
- startTimeRef.current = performance.now();
54
- }
55
-
56
- return enabled ? metricsRef.current : null;
57
- }
58
-
59
- /**
60
- * Hook to track unnecessary re-renders
61
- */
62
- export function useRenderTracker(
63
- componentName: string,
64
- props: Record<string, any>,
65
- enabled: boolean = __DEV__,
66
- ): void {
67
- const prevPropsRef = useRef<Record<string, any> | undefined>(undefined);
68
- const renderCountRef = useRef(0);
69
-
70
- useEffect(() => {
71
- if (!enabled) return;
72
-
73
- renderCountRef.current++;
74
-
75
- if (prevPropsRef.current) {
76
- const changedProps = Object.keys(props).filter(
77
- (key) => props[key] !== prevPropsRef.current![key],
78
- );
79
-
80
- if (changedProps.length === 0) {
81
- console.warn(
82
- `Unnecessary re-render in ${componentName} (render #${renderCountRef.current})`,
83
- );
84
- } else if (renderCountRef.current > 10) {
85
- console.info(
86
- `${componentName} re-rendered due to: ${changedProps.join(', ')}`,
87
- );
88
- }
89
- }
90
-
91
- prevPropsRef.current = {...props};
92
- });
93
- }
package/src/index.tsx DELETED
@@ -1,38 +0,0 @@
1
- // Modals
2
- export * from './components/modals/AlertDialog/AlertDialog';
3
- export * from './components/modals/Snackbar/Snackbar';
4
-
5
- // Common Components
6
- export * from './components/common/ErrorBoundary/ErrorBoundary';
7
-
8
- // Providers
9
- export * from './providers';
10
-
11
- // UIs
12
- export * from './components/uis/Accordion/Accordion';
13
- export * from './components/uis/Button/Button';
14
- export * from './components/uis/Card/Card';
15
- export * from './components/uis/Checkbox/Checkbox';
16
- export * from './components/uis/CustomPressable/CustomPressable';
17
- export * from './components/uis/EditText/EditText';
18
- export * from './components/uis/Fab/Fab';
19
- export * from './components/uis/Hr/Hr';
20
- export * from './components/uis/Icon/Icon';
21
- export * from './components/uis/IconButton/IconButton';
22
- export * from './components/uis/LoadingIndicator/LoadingIndicator';
23
- export * from './components/uis/PinchZoom/PinchZoom';
24
- export * from './components/uis/Rating/Rating';
25
- export * from './components/uis/RadioGroup/RadioGroup';
26
- export * from './components/uis/SegmentedControl/SegmentedControl';
27
- export * from './components/uis/StatusbarBrightness/StatusBarBrightness';
28
- export * from './components/uis/SwitchToggle/SwitchToggle';
29
- export * from './components/uis/Typography/Typography';
30
-
31
- // Hooks
32
- export * from './hooks';
33
-
34
- // Utils
35
- export * from './utils';
36
-
37
- // Types
38
- export * from './types';