Skip to content

Commit 4aff509

Browse files
committed
move textfield from login to components
also added ability to hide the label and custom label widths
1 parent 9d85215 commit 4aff509

File tree

3 files changed

+102
-92
lines changed

3 files changed

+102
-92
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// @flow
2+
import React from 'react'
3+
import {StyleSheet, Text, Platform, TextInput} from 'react-native'
4+
import {Cell} from 'react-native-tableview-simple'
5+
import {Row} from '../../components/layout'
6+
import * as c from '../../components/colors'
7+
8+
const styles = StyleSheet.create({
9+
label: {
10+
width: 90,
11+
fontSize: 16,
12+
marginTop: Platform.OS === 'ios' ? -2 : 0, // lines the label up with the text on iOS
13+
alignSelf: 'center',
14+
},
15+
hiddenLabel: {
16+
width: 0,
17+
},
18+
customTextInput: {
19+
flex: 1,
20+
},
21+
loginCell: {
22+
height: Platform.OS === 'android' ? 65 : 44,
23+
alignItems: 'stretch',
24+
paddingTop: 0,
25+
paddingBottom: 0,
26+
},
27+
})
28+
29+
export class CellTextField extends React.Component {
30+
static defaultProps = {
31+
disabled: false,
32+
placeholder: '',
33+
_ref: () => {},
34+
returnKeyType: 'default',
35+
secureTextEntry: false,
36+
}
37+
38+
props: {
39+
label?: string,
40+
_ref: () => any,
41+
disabled: boolean,
42+
onChangeText: string => any,
43+
onSubmitEditing: string => any,
44+
placeholder: string,
45+
returnKeyType: 'done' | 'next' | 'default',
46+
secureTextEntry: boolean,
47+
value: string,
48+
labelWidth?: number,
49+
}
50+
51+
_input: any
52+
focusInput = () => this._input.focus()
53+
54+
cacheRef = (ref: any) => {
55+
this._input = ref
56+
this.props._ref(ref)
57+
}
58+
59+
onSubmit = () => {
60+
this.props.onSubmitEditing(this.props.value)
61+
}
62+
63+
render() {
64+
const labelWidthStyle = this.props.labelWidth !== null &&
65+
this.props.labelWidth !== undefined
66+
? {width: this.props.labelWidth}
67+
: null
68+
69+
const label = this.props.label
70+
? <Text onPress={this.focusInput} style={[styles.label, labelWidthStyle]}>
71+
{this.props.label}
72+
</Text>
73+
: <Text style={styles.hiddenLabel} />
74+
75+
return (
76+
<Cell
77+
contentContainerStyle={styles.loginCell}
78+
cellContentView={label}
79+
cellAccessoryView={
80+
<TextInput
81+
ref={this.cacheRef}
82+
autoCapitalize="none"
83+
autoCorrect={false}
84+
clearButtonMode="while-editing"
85+
disabled={this.props.disabled}
86+
onChangeText={this.props.onChangeText}
87+
onSubmitEditing={this.onSubmit}
88+
placeholder={this.props.placeholder}
89+
placeholderTextColor={c.iosPlaceholderText}
90+
returnKeyType={this.props.returnKeyType}
91+
secureTextEntry={this.props.secureTextEntry}
92+
style={[styles.customTextInput]}
93+
value={this.props.value}
94+
/>
95+
}
96+
/>
97+
)
98+
}
99+
}

source/views/settings/components/login-field.js

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

source/views/settings/sections/login-credentials.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22
import React from 'react'
33
import {Cell, Section} from 'react-native-tableview-simple'
4-
import {LoginField} from '../components/login-field'
4+
import {CellTextField} from '../../components/cells/textfield'
55
import {LoginButton} from '../components/login-button'
66
import {
77
logInViaCredentials,
@@ -57,7 +57,7 @@ class CredentialsLoginSection extends React.Component {
5757
header="ST. OLAF LOGIN"
5858
footer="St. Olaf login enables the &quot;meals remaining&quot; feature."
5959
>
60-
<LoginField
60+
<CellTextField
6161
label="Username"
6262
_ref={ref => (this._usernameInput = ref)}
6363
disabled={loading}
@@ -69,7 +69,7 @@ class CredentialsLoginSection extends React.Component {
6969
value={username}
7070
/>
7171

72-
<LoginField
72+
<CellTextField
7373
label="Password"
7474
_ref={ref => (this._passwordInput = ref)}
7575
disabled={loading}

0 commit comments

Comments
 (0)