Skip to content

Commit a5fafb1

Browse files
32penkinartyorsh
authored andcommitted
fix(ui): input styles passing and applying fix
1 parent dc89874 commit a5fafb1

File tree

3 files changed

+112
-71
lines changed

3 files changed

+112
-71
lines changed

src/framework/ui/common/props.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,62 @@ export const TextStyleProps: string[] = [
2929
'textAlignVertical',
3030
'includeFontPadding',
3131
];
32+
33+
export const FlexStyleProps: string[] = [
34+
'alignContent',
35+
'alignItems',
36+
'alignSelf',
37+
'aspectRatio',
38+
'borderBottomWidth',
39+
'borderEndWidth',
40+
'borderLeftWidth',
41+
'borderRightWidth',
42+
'borderStartWidth',
43+
'borderTopWidth',
44+
'borderWidth',
45+
'bottom',
46+
'display',
47+
'end',
48+
'flex',
49+
'flexBasis',
50+
'flexDirection',
51+
'flexGrow',
52+
'flexShrink',
53+
'flexWrap',
54+
'height',
55+
'justifyContent',
56+
'left',
57+
'margin',
58+
'marginBottom',
59+
'marginEnd',
60+
'marginHorizontal',
61+
'marginLeft',
62+
'marginRight',
63+
'marginStart',
64+
'marginTop',
65+
'marginVertical',
66+
'maxHeight',
67+
'maxWidth',
68+
'minHeight',
69+
'minWidth',
70+
'overflow',
71+
'padding',
72+
'paddingBottom',
73+
'paddingEnd',
74+
'paddingHorizontal',
75+
'paddingLeft',
76+
'paddingRight',
77+
'paddingStart',
78+
'paddingTop',
79+
'paddingVertical',
80+
'position',
81+
'right',
82+
'start',
83+
'top',
84+
'width',
85+
'zIndex',
86+
87+
// ios
88+
89+
'direction',
90+
];

src/framework/ui/input/input.component.tsx

Lines changed: 53 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
TextInputProps,
77
TextStyle,
88
View,
9-
ViewProps,
109
} from 'react-native';
1110
import {
1211
allWithRest,
@@ -23,26 +22,24 @@ import {
2322
Text as TextComponent,
2423
Props as TextProps,
2524
} from '../text/text.component';
26-
import { TextStyleProps } from '@kitten/ui/common/props';
25+
import {
26+
TextStyleProps,
27+
FlexStyleProps,
28+
} from '../common/props';
2729

2830
const Text = styled<TextProps>(TextComponent);
2931

3032
type IconElement = React.ReactElement<ImageProps>;
31-
type LabelElement = React.ReactElement<TextProps>;
32-
33-
interface CaptionStyles {
34-
container: StyleType;
35-
text: StyleType;
36-
icon: StyleType;
37-
}
33+
type TextElement = React.ReactElement<TextProps>;
34+
type IconProp = (style: StyleType) => React.ReactElement<ImageProps>;
3835

3936
interface InputProps {
4037
status?: string;
4138
disabled?: boolean;
4239
label?: string;
4340
caption?: string;
44-
captionIcon?: (style: StyleType) => React.ReactElement<ImageProps>;
45-
icon?: (style: StyleType) => React.ReactElement<ImageProps>;
41+
captionIcon?: IconProp;
42+
icon?: IconProp;
4643
}
4744

4845
export type Props = InputProps & StyledComponentProps & TextInputProps;
@@ -67,7 +64,8 @@ export class Input extends React.Component<Props> {
6764

6865
private getComponentStyle = (style: StyleType): StyleType => {
6966
const derivedStyle: TextStyle = StyleSheet.flatten(this.props.style);
70-
const { rest: derivedContainerStyle, ...derivedTextStyle } = allWithRest(derivedStyle, TextStyleProps);
67+
const { rest: containerStyle, ...derivedTextStyle } = allWithRest(derivedStyle, TextStyleProps);
68+
const { rest: inputContainerStyle, ...derivedContainerStyle } = allWithRest(containerStyle, FlexStyleProps);
7169

7270
const {
7371
textMarginHorizontal,
@@ -97,12 +95,17 @@ export class Input extends React.Component<Props> {
9795

9896
return {
9997
container: {
100-
...derivedContainerStyle,
10198
...styles.container,
99+
...derivedContainerStyle,
102100
},
103101
inputContainer: {
104102
...containerParameters,
105103
...styles.inputContainer,
104+
...inputContainerStyle,
105+
},
106+
captionContainer: {
107+
marginTop: captionMarginTop,
108+
...styles.captionContainer,
106109
},
107110
text: {
108111
marginHorizontal: textMarginHorizontal,
@@ -127,80 +130,59 @@ export class Input extends React.Component<Props> {
127130
fontWeight: labelFontWeight,
128131
...styles.label,
129132
},
130-
caption: {
131-
text: {
132-
color: captionTextColor,
133-
fontSize: captionTextFontSize,
134-
fontWeight: captionTextFontWeight,
135-
lineHeight: captionTextLineHeight,
136-
},
137-
icon: {
138-
width: captionIconWidth,
139-
height: captionIconHeight,
140-
tintColor: captionIconTintColor,
141-
marginRight: captionIconMarginRight,
142-
},
143-
container: {
144-
marginTop: captionMarginTop,
145-
...styles.captionContainer,
146-
},
133+
captionIcon: {
134+
width: captionIconWidth,
135+
height: captionIconHeight,
136+
tintColor: captionIconTintColor,
137+
marginRight: captionIconMarginRight,
138+
...styles.captionIcon,
139+
},
140+
captionLabel: {
141+
fontSize: captionTextFontSize,
142+
fontWeight: captionTextFontWeight,
143+
lineHeight: captionTextLineHeight,
144+
color: captionTextColor,
145+
...styles.captionLabel,
147146
},
148147
};
149148
};
150149

151-
private renderIconElement = (style: StyleType,
152-
icon: (style: StyleType) => IconElement): IconElement | null => {
153-
154-
return icon ? icon(style) : null;
150+
private renderIconElement = (style: StyleType, icon: IconProp): IconElement => {
151+
return icon(style);
155152
};
156153

157-
private renderTextElement = (style: StyleType, text: string): LabelElement => {
154+
private renderTextElement = (style: StyleType, text: string): TextElement => {
158155
return (
159156
<Text style={style}>{text}</Text>
160157
);
161158
};
162159

163-
private renderText = (style: StyleType, text: string): LabelElement | null => {
164-
const hasText: boolean = text && text.length !== 0;
165-
166-
return hasText ? this.renderTextElement(style, text) : null;
167-
};
160+
public render(): React.ReactElement<TextInputProps> {
161+
const { themedStyle, disabled, label, icon, caption, captionIcon, ...restProps } = this.props;
162+
const style: StyleType = this.getComponentStyle(themedStyle);
168163

169-
private renderCaptionElement = (style: CaptionStyles): React.ReactElement<ViewProps> | null => {
170-
const { caption, captionIcon } = this.props;
171-
const icon: IconElement | null = this.renderIconElement(style.icon, captionIcon);
172-
const text: LabelElement | null = this.renderText(style.text, caption);
164+
const iconElement: IconElement = icon ? this.renderIconElement(style.icon, icon) : null;
165+
const labelElement: TextElement = label ? this.renderTextElement(style.label, label) : null;
166+
const captionIconElement: IconElement = captionIcon ? this.renderIconElement(style.captionIcon, captionIcon) : null;
167+
const captionLabelElement: TextElement = caption ? this.renderTextElement(style.captionLabel, caption) : null;
173168

174169
return (
175170
<View style={style.container}>
176-
{icon}
177-
{text}
178-
</View>
179-
);
180-
};
181-
182-
public render(): React.ReactElement<TextInputProps> {
183-
const { themedStyle, disabled, label, icon, ...restProps } = this.props;
184-
const componentStyle: StyleType = this.getComponentStyle(themedStyle);
185-
const inputIcon: IconElement | null = this.renderIconElement(componentStyle.icon, icon);
186-
const inputLabel: LabelElement | null = this.renderText(componentStyle.label, label);
187-
const caption: React.ReactElement<ViewProps> | null =
188-
this.renderCaptionElement(componentStyle.caption);
189-
190-
return (
191-
<View style={componentStyle.container}>
192-
{inputLabel}
193-
<View style={componentStyle.inputContainer}>
171+
{labelElement}
172+
<View style={style.inputContainer}>
194173
<TextInput
195174
{...restProps}
175+
style={style.text}
196176
editable={!disabled}
197177
onFocus={this.onFocus}
198178
onEndEditing={this.onEndEditing}
199-
style={componentStyle.text}
200179
/>
201-
{inputIcon}
180+
{iconElement}
181+
</View>
182+
<View style={style.captionContainer}>
183+
{captionIconElement}
184+
{captionLabelElement}
202185
</View>
203-
{caption}
204186
</View>
205187
);
206188
}
@@ -214,13 +196,15 @@ const styles = StyleSheet.create({
214196
flexDirection: 'row',
215197
alignItems: 'center',
216198
},
199+
captionContainer: {
200+
flexDirection: 'row',
201+
alignItems: 'center',
202+
},
217203
text: {
218204
flex: 1,
219205
},
220206
icon: {},
221207
label: {},
222-
captionContainer: {
223-
flexDirection: 'row',
224-
alignItems: 'center',
225-
},
208+
captionIcon: {},
209+
captionLabel: {},
226210
});

src/framework/ui/input/input.spec.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ exports[`@input: matches snapshot * appearance * label + caption 1`] = `
212212
<TextInput
213213
allowFontScaling={true}
214214
appearance="default"
215-
caption="Caption Text"
216-
captionIcon={[Function]}
217215
dispatch={[Function]}
218216
editable={true}
219217
onEndEditing={[Function]}

0 commit comments

Comments
 (0)