Skip to content

Commit f336aff

Browse files
committed
chore: code composition refactor wip
1 parent fa36486 commit f336aff

12 files changed

Lines changed: 193 additions & 316 deletions

File tree

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { PixelRatio, Platform } from 'react-native';
1+
import { I18nManager, PixelRatio, Platform } from 'react-native';
22

3-
// ==================
4-
// PLATFORM
5-
// ==================
63
export const isWeb = Platform.OS === 'web';
74

85
export const fontScale = PixelRatio.getFontScale();
96

10-
// =====================
11-
// FIELD LAYOUT
12-
// =====================
7+
/**
8+
* Common constants for the text field component.
9+
*/
10+
11+
// Field layout
1312
export const BASELINE_TEXT_FIELD_HEIGHT = 56;
1413
export const BASELINE_TEXT_FIELD_PADDING_VERTICAL = 8;
1514

@@ -20,19 +19,20 @@ export const TEXT_FIELD_HEIGHT = BASELINE_TEXT_FIELD_HEIGHT * fontScale;
2019
export const TEXT_FIELD_PADDING_VERTICAL =
2120
BASELINE_TEXT_FIELD_PADDING_VERTICAL * fontScale;
2221

23-
// ==================
24-
// ACCESSORY
25-
// ==================
22+
export const TEXT_FIELD_BORDER_RADIUS = 4;
23+
24+
export const LABEL_START_OFFSET_WITHOUT_ACCESSORY =
25+
TEXT_FIELD_INPUT_WRAPPER_PADDING_HORIZONTAL;
26+
27+
// Accessory
2628
export const ACCESSORY_SIZE = 24;
2729

2830
export const PREFIX_END_PADDING = 2;
2931
export const SUFFIX_START_PADDING = 2;
3032

3133
export const ERROR_ICON_SIZE = 16;
3234

33-
// ===============
34-
// TYPOGRAPHY
35-
// ===============
35+
// Typography
3636
export const LINE_HEIGHT_DELTA = 2;
3737
export const INPUT_FONT_SIZE = 16;
3838
export const ACTIVE_LABEL_FONT_SIZE = 12;
@@ -48,29 +48,67 @@ export const INACTIVE_LABEL_TOP_POSITION =
4848
LINE_HEIGHT_DELTA) *
4949
fontScale;
5050

51-
// =================
52-
// HELPER TEXT LAYOUT
53-
// =================
51+
// Helper text layout
5452
export const SUPPORTING_TEXT_MARGIN_TOP = 4;
5553

56-
// =========
57-
// ANIMATION
58-
// =========
54+
// Animation
5955
export const ANIMATION_DURATION_MS = 150;
6056

61-
// =========
62-
// INDICATOR
63-
// =========
57+
// Indicator
6458
export const ACTIVE_INDICATOR_SIZE = 2;
6559
export const INACTIVE_INDICATOR_SIZE = 1;
6660

67-
// ============
68-
// SHAPE
69-
// ============
70-
export const TEXT_FIELD_BORDER_RADIUS = 4;
61+
// Layout support
62+
const isRTL = I18nManager.getConstants().isRTL;
63+
const layoutSupportMultiplier = isRTL ? -1 : 1;
7164

72-
// ==================
73-
// LABEL POSITIONING
74-
// ==================
75-
export const LABEL_START_OFFSET_WITHOUT_ACCESSORY =
65+
/**
66+
* Constants for the filled variant.
67+
*/
68+
69+
export const FILLED_LABEL_START_OFFSET_WITH_ACCESSORY =
70+
ACCESSORY_SIZE +
71+
TEXT_FIELD_ACCESSORY_MARGIN_HORIZONTAL +
7672
TEXT_FIELD_INPUT_WRAPPER_PADDING_HORIZONTAL;
73+
74+
export const FILLED_ACTIVE_LABEL_TOP_POSITION = TEXT_FIELD_PADDING_VERTICAL;
75+
76+
export const FILLED_MULTILINE_PADDING_TOP =
77+
ACTIVE_LABEL_FONT_SIZE * fontScale + TEXT_FIELD_PADDING_VERTICAL;
78+
79+
export const FILLED_DISABLED_CONTAINER_OPACITY = 0.04;
80+
81+
/**
82+
* Constants for the outlined variant.
83+
*/
84+
85+
export const OUTLINED_DISABLED_OUTLINE_OPACITY = 0.12;
86+
87+
export const OUTLINED_MULTILINE_PADDING_TOP =
88+
((BASELINE_TEXT_FIELD_HEIGHT -
89+
2 * BASELINE_TEXT_FIELD_PADDING_VERTICAL -
90+
INPUT_FONT_SIZE) /
91+
2 -
92+
LINE_HEIGHT_DELTA) *
93+
fontScale;
94+
95+
// Label positioning
96+
export const OUTLINED_LABEL_PADDING_HORIZONTAL = 4;
97+
98+
export const OUTLINED_LABEL_START_OFFSET_WITH_ACCESSORY =
99+
ACCESSORY_SIZE +
100+
TEXT_FIELD_ACCESSORY_MARGIN_HORIZONTAL +
101+
TEXT_FIELD_INPUT_WRAPPER_PADDING_HORIZONTAL -
102+
OUTLINED_LABEL_PADDING_HORIZONTAL;
103+
104+
export const OUTLINED_ACTIVE_LABEL_TOP_POSITION =
105+
(-BASELINE_TEXT_FIELD_PADDING_VERTICAL + LINE_HEIGHT_DELTA) * fontScale;
106+
107+
export const OUTLINED_LABEL_TRANSLATE_X_WITH_ACCESSORY =
108+
-layoutSupportMultiplier *
109+
(ACCESSORY_SIZE +
110+
TEXT_FIELD_INPUT_WRAPPER_PADDING_HORIZONTAL -
111+
OUTLINED_LABEL_PADDING_HORIZONTAL);
112+
113+
export const OUTLINED_LABEL_TRANSLATE_X_WITHOUT_ACCESSORY =
114+
-layoutSupportMultiplier * OUTLINED_LABEL_PADDING_HORIZONTAL;

src/components/TextField/filled/constants.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/components/TextField/filled/logic.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ import {
1010
TEXT_FIELD_BORDER_RADIUS,
1111
isWeb,
1212
} from '../constants';
13-
import { styles } from '../styles';
13+
import {
14+
FILLED_LABEL_START_OFFSET_WITH_ACCESSORY,
15+
FILLED_MULTILINE_PADDING_TOP,
16+
} from '../constants';
17+
import { filledStyles, styles } from '../styles';
1418
import type {
1519
FilledTextFieldHookData,
1620
TextFieldProps,
1721
TextFieldSharedApi,
1822
} from '../TextField';
19-
import { getFieldBackgroundColor, getSharedTextFieldStyleData } from '../utils';
2023
import {
21-
LABEL_START_OFFSET_WITH_ACCESSORY,
22-
MULTILINE_PADDING_TOP,
23-
} from './constants';
24-
import { filledStyles } from './styles';
25-
import { getOutlineColor } from './utils';
24+
getFieldBackgroundColor,
25+
getOutlineColor,
26+
getSharedTextFieldStyleData,
27+
} from '../utils';
2628

2729
export const getFilledTextFieldData = (
2830
api: TextFieldSharedApi,
@@ -47,9 +49,7 @@ export const getFilledTextFieldData = (
4749
animatedActiveOutlineStyle,
4850
} = api;
4951

50-
// =======================
51-
// THEME TOKENS
52-
// =======================
52+
// Theme tokens
5353

5454
const {
5555
colors: { onSurface },
@@ -71,23 +71,19 @@ export const getFilledTextFieldData = (
7171

7272
const fieldBackgroundColor = getFieldBackgroundColor({ theme, disabled });
7373

74-
// =======================
75-
// SHARED STYLES
76-
// =======================
74+
// Shared styles
7775

7876
const shared = getSharedTextFieldStyleData(api, props);
7977

80-
// =======================
81-
// VARIANT-SPECIFIC STYLES
82-
// =======================
78+
// Variant-specific styles
8379

8480
const animatedLabelWrapperStyles: StyleProp<
8581
AnimatedStyle<StyleProp<ViewStyle>>
8682
> = [
8783
filledStyles.labelWrapper,
8884
{
8985
left: hasAccessory
90-
? LABEL_START_OFFSET_WITH_ACCESSORY
86+
? FILLED_LABEL_START_OFFSET_WITH_ACCESSORY
9187
: LABEL_START_OFFSET_WITHOUT_ACCESSORY,
9288
},
9389
animatedLabelWrapperStyle,
@@ -156,7 +152,7 @@ export const getFilledTextFieldData = (
156152
},
157153
textInputProps.multiline && {
158154
height: 'auto',
159-
paddingTop: MULTILINE_PADDING_TOP,
155+
paddingTop: FILLED_MULTILINE_PADDING_TOP,
160156
},
161157
isWeb && {
162158
outlineStyle: 'none' as TextStyle['outlineStyle'],

src/components/TextField/filled/styles.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/components/TextField/filled/utils.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)