feat: add column layout to settings fields

This commit is contained in:
Bettenbuk Zoltan 2020-03-25 11:51:35 +01:00 committed by Saúl Ibarra Corretgé
parent ed5d2e3907
commit e5d2304427
3 changed files with 57 additions and 13 deletions

View File

@ -27,6 +27,11 @@ type Props = {
*/ */
label: string, label: string,
/**
* One of 'row' (default) or 'column'.
*/
layout: string,
/** /**
* Invoked to obtain translated strings. * Invoked to obtain translated strings.
*/ */
@ -60,7 +65,7 @@ class FormRow extends Component<Props> {
* @returns {ReactElement} * @returns {ReactElement}
*/ */
render() { render() {
const { t } = this.props; const { layout, t } = this.props;
// Some field types need additional props to look good and standardized // Some field types need additional props to look good and standardized
// on a form. // on a form.
@ -76,7 +81,8 @@ class FormRow extends Component<Props> {
<Text <Text
style = { [ style = { [
styles.text, styles.text,
styles.fieldLabelText styles.fieldLabelText,
layout === 'column' ? styles.fieldLabelTextColumn : undefined
] } > ] } >
{ t(this.props.label) } { t(this.props.label) }
</Text> </Text>
@ -108,7 +114,10 @@ class FormRow extends Component<Props> {
case 'TextInput': case 'TextInput':
return { return {
placeholderTextColor: PLACEHOLDER_COLOR, placeholderTextColor: PLACEHOLDER_COLOR,
style: styles.textInputField, style: [
styles.textInputField,
this.props.layout === 'column' ? styles.textInputFieldColumn : undefined
],
underlineColorAndroid: ANDROID_UNDERLINE_COLOR underlineColorAndroid: ANDROID_UNDERLINE_COLOR
}; };
} }
@ -126,14 +135,21 @@ class FormRow extends Component<Props> {
* @returns {Array<Object>} * @returns {Array<Object>}
*/ */
_getRowStyle() { _getRowStyle() {
const { fieldSeparator, layout } = this.props;
const rowStyle = [ const rowStyle = [
styles.fieldContainer styles.fieldContainer
]; ];
if (this.props.fieldSeparator) { if (fieldSeparator) {
rowStyle.push(styles.fieldSeparator); rowStyle.push(styles.fieldSeparator);
} }
if (layout === 'column') {
rowStyle.push(
styles.fieldContainerColumn
);
}
return rowStyle; return rowStyle;
} }
} }

View File

@ -361,14 +361,17 @@ class SettingsView extends AbstractSettingsView<Props, State> {
label = 'settingsView.profileSection' /> label = 'settingsView.profileSection' />
<FormRow <FormRow
fieldSeparator = { true } fieldSeparator = { true }
label = 'settingsView.displayName'> label = 'settingsView.displayName'
layout = 'column'>
<TextInput <TextInput
autoCorrect = { false } autoCorrect = { false }
onChangeText = { this._onChangeDisplayName } onChangeText = { this._onChangeDisplayName }
placeholder = 'John Doe' placeholder = 'John Doe'
value = { displayName } /> value = { displayName } />
</FormRow> </FormRow>
<FormRow label = 'settingsView.email'> <FormRow
label = 'settingsView.email'
layout = 'column'>
<TextInput <TextInput
autoCapitalize = 'none' autoCapitalize = 'none'
autoCorrect = { false } autoCorrect = { false }
@ -381,7 +384,8 @@ class SettingsView extends AbstractSettingsView<Props, State> {
label = 'settingsView.conferenceSection' /> label = 'settingsView.conferenceSection' />
<FormRow <FormRow
fieldSeparator = { true } fieldSeparator = { true }
label = 'settingsView.serverURL'> label = 'settingsView.serverURL'
layout = 'column'>
<TextInput <TextInput
autoCapitalize = 'none' autoCapitalize = 'none'
autoCorrect = { false } autoCorrect = { false }

View File

@ -1,7 +1,4 @@
import { import { ColorPalette } from '../../../base/styles';
ColorPalette,
createStyleSheet
} from '../../../base/styles';
export const ANDROID_UNDERLINE_COLOR = 'transparent'; export const ANDROID_UNDERLINE_COLOR = 'transparent';
export const PLACEHOLDER_COLOR = ColorPalette.lightGrey; export const PLACEHOLDER_COLOR = ColorPalette.lightGrey;
@ -11,7 +8,7 @@ const TEXT_SIZE = 17;
/** /**
* The styles of the native components of the feature {@code settings}. * The styles of the native components of the feature {@code settings}.
*/ */
export default createStyleSheet({ export default {
/** /**
* Standardized style for a field container {@code View}. * Standardized style for a field container {@code View}.
*/ */
@ -22,6 +19,15 @@ export default createStyleSheet({
paddingHorizontal: 8 paddingHorizontal: 8
}, },
/**
* * Appended style for column layout fields.
*/
fieldContainerColumn: {
alignItems: 'flex-start',
flexDirection: 'column',
paddingVertical: 3
},
/** /**
* Standard container for a {@code View} containing a field label. * Standard container for a {@code View} containing a field label.
*/ */
@ -38,6 +44,13 @@ export default createStyleSheet({
fontSize: TEXT_SIZE fontSize: TEXT_SIZE
}, },
/**
* Appended style for column layout fields.
*/
fieldLabelTextColumn: {
fontSize: 12
},
/** /**
* Field container style for all but last row {@code View}. * Field container style for all but last row {@code View}.
*/ */
@ -85,5 +98,16 @@ export default createStyleSheet({
flex: 1, flex: 1,
fontSize: TEXT_SIZE, fontSize: TEXT_SIZE,
textAlign: 'right' textAlign: 'right'
},
/**
* Appended style for column layout fields.
*/
textInputFieldColumn: {
backgroundColor: 'rgb(245, 245, 245)',
borderRadius: 8,
marginVertical: 5,
paddingVertical: 3,
textAlign: 'left'
} }
}); };