cpk-ui 0.5.4 → 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 (136) 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 +2 -1
  9. package/components/uis/Button/Button.d.ts.map +1 -1
  10. package/components/uis/Button/Button.js +11 -11
  11. package/components/uis/Card/Card.d.ts +2 -1
  12. package/components/uis/Card/Card.d.ts.map +1 -1
  13. package/components/uis/Card/Card.js +12 -3
  14. package/components/uis/Checkbox/Checkbox.d.ts +2 -1
  15. package/components/uis/Checkbox/Checkbox.d.ts.map +1 -1
  16. package/components/uis/Checkbox/Checkbox.js +2 -2
  17. package/components/uis/CustomPressable/CustomPressable.d.ts.map +1 -1
  18. package/components/uis/CustomPressable/CustomPressable.js +6 -6
  19. package/components/uis/EditText/EditText.d.ts +1 -0
  20. package/components/uis/EditText/EditText.d.ts.map +1 -1
  21. package/components/uis/EditText/EditText.js +18 -13
  22. package/components/uis/Fab/Fab.d.ts +2 -2
  23. package/components/uis/Fab/Fab.d.ts.map +1 -1
  24. package/components/uis/Fab/Fab.js +22 -4
  25. package/components/uis/Icon/Icon.d.ts.map +1 -1
  26. package/components/uis/Icon/Icon.js +6 -3
  27. package/components/uis/IconButton/IconButton.d.ts +2 -1
  28. package/components/uis/IconButton/IconButton.d.ts.map +1 -1
  29. package/components/uis/IconButton/IconButton.js +44 -42
  30. package/components/uis/LoadingIndicator/LoadingIndicator.d.ts +2 -1
  31. package/components/uis/LoadingIndicator/LoadingIndicator.d.ts.map +1 -1
  32. package/components/uis/LoadingIndicator/LoadingIndicator.js +4 -4
  33. package/components/uis/RadioGroup/RadioButton.d.ts +2 -1
  34. package/components/uis/RadioGroup/RadioButton.d.ts.map +1 -1
  35. package/components/uis/RadioGroup/RadioButton.js +2 -2
  36. package/components/uis/RadioGroup/RadioGroup.d.ts.map +1 -1
  37. package/components/uis/RadioGroup/RadioGroup.js +16 -3
  38. package/components/uis/Rating/Rating.d.ts.map +1 -1
  39. package/components/uis/Rating/Rating.js +23 -19
  40. package/components/uis/SegmentedControl/SegmentedControl.d.ts.map +1 -1
  41. package/components/uis/SegmentedControl/SegmentedControl.js +1 -1
  42. package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts +2 -2
  43. package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts.map +1 -1
  44. package/components/uis/StatusbarBrightness/StatusBarBrightness.js +1 -1
  45. package/components/uis/SwitchToggle/SwitchToggle.d.ts +2 -1
  46. package/components/uis/SwitchToggle/SwitchToggle.d.ts.map +1 -1
  47. package/components/uis/SwitchToggle/SwitchToggle.js +2 -2
  48. package/hooks/useHoverState.d.ts +8 -0
  49. package/hooks/useHoverState.d.ts.map +1 -0
  50. package/hooks/useHoverState.js +16 -0
  51. package/package.json +18 -6
  52. package/providers/ThemeProvider.d.ts.map +1 -1
  53. package/providers/ThemeProvider.js +0 -1
  54. package/providers/index.d.ts.map +1 -1
  55. package/providers/index.js +3 -2
  56. package/components/uis/Icon/selection.json +0 -1
  57. package/src/components/common/ErrorBoundary/ErrorBoundary.tsx +0 -75
  58. package/src/components/modals/AlertDialog/AlertDialog.stories.tsx +0 -216
  59. package/src/components/modals/AlertDialog/AlertDialog.test.tsx +0 -251
  60. package/src/components/modals/AlertDialog/AlertDialog.tsx +0 -356
  61. package/src/components/modals/Snackbar/Snackbar.stories.tsx +0 -182
  62. package/src/components/modals/Snackbar/Snackbar.test.tsx +0 -319
  63. package/src/components/modals/Snackbar/Snackbar.tsx +0 -260
  64. package/src/components/modals/Snackbar/const.ts +0 -4
  65. package/src/components/uis/Accordion/Accordion.stories.tsx +0 -167
  66. package/src/components/uis/Accordion/Accordion.test.tsx +0 -272
  67. package/src/components/uis/Accordion/Accordion.tsx +0 -109
  68. package/src/components/uis/Accordion/AccordionItem.tsx +0 -306
  69. package/src/components/uis/Button/Button.stories.tsx +0 -218
  70. package/src/components/uis/Button/Button.test.tsx +0 -620
  71. package/src/components/uis/Button/Button.tsx +0 -436
  72. package/src/components/uis/Card/Card.test.tsx +0 -146
  73. package/src/components/uis/Card/Card.tsx +0 -102
  74. package/src/components/uis/Checkbox/Checkbox.stories.tsx +0 -216
  75. package/src/components/uis/Checkbox/Checkbox.test.tsx +0 -173
  76. package/src/components/uis/Checkbox/Checkbox.tsx +0 -220
  77. package/src/components/uis/CustomPressable/CustomPressable.tsx +0 -48
  78. package/src/components/uis/EditText/EditText.stories.tsx +0 -124
  79. package/src/components/uis/EditText/EditText.test.tsx +0 -477
  80. package/src/components/uis/EditText/EditText.tsx +0 -590
  81. package/src/components/uis/Fab/Fab.stories.tsx +0 -133
  82. package/src/components/uis/Fab/Fab.test.tsx +0 -110
  83. package/src/components/uis/Fab/Fab.tsx +0 -168
  84. package/src/components/uis/Hr/Hr.test.tsx +0 -26
  85. package/src/components/uis/Hr/Hr.tsx +0 -19
  86. package/src/components/uis/Icon/Icon.stories.tsx +0 -98
  87. package/src/components/uis/Icon/Icon.test.tsx +0 -49
  88. package/src/components/uis/Icon/Icon.tsx +0 -3819
  89. package/src/components/uis/IconButton/IconButton.test.tsx +0 -165
  90. package/src/components/uis/IconButton/IconButton.tsx +0 -275
  91. package/src/components/uis/LoadingIndicator/LoadingIndicator.tsx +0 -126
  92. package/src/components/uis/LoadingIndicator/LodingIndicator.stories.tsx +0 -81
  93. package/src/components/uis/PinchZoom/PinchZoom.stories.tsx +0 -266
  94. package/src/components/uis/PinchZoom/PinchZoom.test.tsx +0 -113
  95. package/src/components/uis/PinchZoom/PinchZoom.tsx +0 -424
  96. package/src/components/uis/RadioGroup/RadioButton.tsx +0 -188
  97. package/src/components/uis/RadioGroup/RadioGroup.stories.tsx +0 -188
  98. package/src/components/uis/RadioGroup/RadioGroup.test.tsx +0 -287
  99. package/src/components/uis/RadioGroup/RadioGroup.tsx +0 -109
  100. package/src/components/uis/Rating/Rating.test.tsx +0 -98
  101. package/src/components/uis/Rating/Rating.tsx +0 -200
  102. package/src/components/uis/SegmentedControl/SegmentedControl.stories.tsx +0 -546
  103. package/src/components/uis/SegmentedControl/SegmentedControl.test.tsx +0 -274
  104. package/src/components/uis/SegmentedControl/SegmentedControl.tsx +0 -229
  105. package/src/components/uis/StatusbarBrightness/StatusBarBrightness.test.tsx +0 -41
  106. package/src/components/uis/StatusbarBrightness/StatusBarBrightness.tsx +0 -26
  107. package/src/components/uis/Styled/StyledComponents.tsx +0 -217
  108. package/src/components/uis/SwitchToggle/SwitchToggle.stories.tsx +0 -75
  109. package/src/components/uis/SwitchToggle/SwitchToggle.test.tsx +0 -105
  110. package/src/components/uis/SwitchToggle/SwitchToggle.tsx +0 -305
  111. package/src/components/uis/Typography/Typography.stories.tsx +0 -149
  112. package/src/components/uis/Typography/Typography.test.tsx +0 -58
  113. package/src/components/uis/Typography/Typography.tsx +0 -386
  114. package/src/hooks/index.ts +0 -2
  115. package/src/hooks/useAnimations.ts +0 -71
  116. package/src/hooks/useDebouncedColorScheme.tsx +0 -30
  117. package/src/hooks/useOptimizedStyles.ts +0 -22
  118. package/src/hooks/usePerformance.ts +0 -93
  119. package/src/index.tsx +0 -38
  120. package/src/providers/ThemeProvider.tsx +0 -177
  121. package/src/providers/index.tsx +0 -130
  122. package/src/test/testUtils.tsx +0 -101
  123. package/src/types/common.ts +0 -77
  124. package/src/types/index.ts +0 -1
  125. package/src/types/kstyled.d.ts +0 -6
  126. package/src/utils/accessibility.ts +0 -110
  127. package/src/utils/colors.ts +0 -151
  128. package/src/utils/createCtx.tsx +0 -26
  129. package/src/utils/guards.ts +0 -93
  130. package/src/utils/index.ts +0 -2
  131. package/src/utils/performanceTest.ts +0 -174
  132. package/src/utils/platform.ts +0 -69
  133. package/src/utils/theme.ts +0 -38
  134. package/test/testUtils.d.ts +0 -113
  135. package/test/testUtils.d.ts.map +0 -1
  136. package/test/testUtils.js +0 -65
@@ -1,149 +0,0 @@
1
- import type {Meta, StoryObj} from '@storybook/react';
2
- import {Typography} from './Typography';
3
- import {withThemeProvider} from '../../../../.storybook/decorators';
4
- import {ScrollView, View} from 'react-native';
5
- import {ThemeParam} from '../../../utils/theme';
6
-
7
- const meta = {
8
- title: 'Typography',
9
- component: Typography.Title,
10
- parameters: {
11
- notes: `
12
- A comprehensive typography system with predefined text styles for consistent design.
13
-
14
- ## Features
15
- - **Pre-defined Text Styles**: Multiple typography variants for different use cases
16
- - **Theme Integration**: Automatically uses theme colors and styles
17
- - **Responsive**: Works across all platforms (iOS, Android, Web)
18
- - **Customizable**: Can override styles while maintaining base typography
19
-
20
- ## Available Typography Variants
21
- - **Title**: Large heading text
22
- - **Heading1**: Primary heading
23
- - **Heading2**: Secondary heading
24
- - **Heading3**: Tertiary heading
25
- - **Subtitle1**: Large subtitle
26
- - **Subtitle2**: Standard subtitle
27
- - **Body1**: Primary body text
28
- - **Body2**: Secondary body text
29
- - **Body3**: Tertiary body text
30
- - **Body4**: Small body text
31
- - **Caption**: Small caption text
32
- - **Button**: Button text style
33
-
34
- ## Usage
35
- \`\`\`tsx
36
- <Typography.Title>Page Title</Typography.Title>
37
- <Typography.Heading1>Main Heading</Typography.Heading1>
38
- <Typography.Body1>This is body text.</Typography.Body1>
39
- <Typography.Caption>Small caption text</Typography.Caption>
40
- \`\`\`
41
-
42
- ### With Custom Styling
43
- \`\`\`tsx
44
- <Typography.Body1 style={{color: 'blue', fontWeight: 'bold'}}>
45
- Custom styled text
46
- </Typography.Body1>
47
- \`\`\`
48
- `,
49
- docs: {
50
- description: {
51
- component: `
52
- A comprehensive typography system with predefined text styles for consistent design.
53
-
54
- ## Features
55
- - **Pre-defined Text Styles**: Multiple typography variants for different use cases
56
- - **Theme Integration**: Automatically uses theme colors and styles
57
- - **Responsive**: Works across all platforms (iOS, Android, Web)
58
- - **Customizable**: Can override styles while maintaining base typography
59
-
60
- ## Available Typography Variants
61
- - **Title**: Large heading text
62
- - **Heading1**: Primary heading
63
- - **Heading2**: Secondary heading
64
- - **Heading3**: Tertiary heading
65
- - **Subtitle1**: Large subtitle
66
- - **Subtitle2**: Standard subtitle
67
- - **Body1**: Primary body text
68
- - **Body2**: Secondary body text
69
- - **Body3**: Tertiary body text
70
- - **Body4**: Small body text
71
- - **Caption**: Small caption text
72
- - **Button**: Button text style
73
-
74
- ## Usage
75
- \`\`\`tsx
76
- <Typography.Title>Page Title</Typography.Title>
77
- <Typography.Heading1>Main Heading</Typography.Heading1>
78
- <Typography.Body1>This is body text.</Typography.Body1>
79
- <Typography.Caption>Small caption text</Typography.Caption>
80
- \`\`\`
81
-
82
- ### With Custom Styling
83
- \`\`\`tsx
84
- <Typography.Body1 style={{color: 'blue', fontWeight: 'bold'}}>
85
- Custom styled text
86
- </Typography.Body1>
87
- \`\`\`
88
- `,
89
- },
90
- },
91
- },
92
- argTypes: {},
93
- decorators: [withThemeProvider],
94
- } satisfies Meta<typeof Typography.Title>;
95
-
96
- export default meta;
97
-
98
- type Story = StoryObj<typeof meta>;
99
-
100
- export const AllTypography: Story = {
101
- render: (args) => (
102
- <ScrollView contentContainerStyle={{padding: 16}}>
103
- {Object.entries(Typography).map(([key, Component]) => (
104
- <View key={key} style={{marginBottom: 16}}>
105
- <Component {...args}>
106
- {key} {args.children}
107
- </Component>
108
- </View>
109
- ))}
110
- </ScrollView>
111
- ),
112
- args: {
113
- children: 'Hello world',
114
- },
115
- argTypes: {
116
- theme: {
117
- control: 'select',
118
- options: ['light', 'dark'],
119
- },
120
- },
121
- };
122
-
123
- export const CustomTitle: Story = {
124
- args: {
125
- children: 'Custom Color',
126
- // @ts-ignore
127
- theme: {
128
- light: {
129
- text: {
130
- basic: 'blue',
131
- },
132
- },
133
- dark: {
134
- text: {
135
- basic: 'skyblue',
136
- },
137
- },
138
- } as ThemeParam,
139
- },
140
- decorators: [
141
- (Story, context) =>
142
- withThemeProvider(
143
- Story,
144
- context,
145
- // @ts-ignore
146
- context.args.theme as ThemeParam,
147
- ),
148
- ],
149
- };
@@ -1,58 +0,0 @@
1
- import React, {type ReactElement} from 'react';
2
- import {View} from 'react-native';
3
- import type {RenderAPI} from '@testing-library/react-native';
4
- import {render} from '@testing-library/react-native';
5
-
6
- import {createComponent} from '../../../../test/testUtils';
7
- import {Typography, TypographyInverted} from './Typography';
8
- import {ThemeProvider} from '../../../providers/ThemeProvider';
9
-
10
- let testingLib: RenderAPI;
11
-
12
- const Component = (): ReactElement =>
13
- createComponent(
14
- <View>
15
- <Typography.Title />,
16
- <Typography.Heading1 />,
17
- <Typography.Heading2 />,
18
- <Typography.Heading3 />,
19
- <Typography.Body1 />,
20
- <Typography.Body2 />,
21
- <TypographyInverted.Title />
22
- <TypographyInverted.Heading1 />
23
- <TypographyInverted.Heading2 />
24
- <TypographyInverted.Heading3 />
25
- <TypographyInverted.Body1 />
26
- <TypographyInverted.Body2 />
27
- </View>,
28
- );
29
-
30
- describe('[Typography]', () => {
31
- it('should render without crashing', () => {
32
- testingLib = render(<Component />);
33
-
34
- const json = testingLib.toJSON();
35
-
36
- expect(json).toBeTruthy();
37
- });
38
-
39
- it('should render default theme', () => {
40
- testingLib = render(Component());
41
-
42
- const json = testingLib.toJSON();
43
-
44
- expect(json).toBeTruthy();
45
- });
46
-
47
- it('should render [dark] mode', () => {
48
- testingLib = render(
49
- <ThemeProvider initialThemeType="dark">
50
- <Component />
51
- </ThemeProvider>,
52
- );
53
-
54
- const json = testingLib.toJSON();
55
-
56
- expect(json).toBeTruthy();
57
- });
58
- });
@@ -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
- }