Skip to content

Commit f8eb357

Browse files
authored
Merge branch 'stateful-list-split' into split-building-hours-helpers
2 parents 161b007 + 691d3d7 commit f8eb357

File tree

18 files changed

+242
-164
lines changed

18 files changed

+242
-164
lines changed

source/views/building-hours/detail/schedule-row.android.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ import {formatBuildingTimes, summarizeDays} from '../lib'
1212

1313
export class ScheduleRow extends React.PureComponent {
1414
props: {
15-
schedule: SingleBuildingScheduleType,
15+
set: SingleBuildingScheduleType,
1616
isActive: boolean,
1717
now: moment,
1818
}
1919

2020
render() {
21-
const {schedule, isActive, now} = this.props
21+
const {set, isActive, now} = this.props
2222
return (
2323
<View style={styles.scheduleRow}>
2424
<StyledText style={[styles.scheduleDays, isActive && styles.bold]}>
25-
{summarizeDays(schedule.days)}
25+
{summarizeDays(set.days)}
2626
</StyledText>
2727

2828
<StyledText style={[styles.scheduleHours, isActive && styles.bold]}>
29-
{formatBuildingTimes(schedule, now)}
29+
{formatBuildingTimes(set, now)}
3030
</StyledText>
3131
</View>
3232
)

source/views/building-hours/detail/schedule-row.ios.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ import {formatBuildingTimes, summarizeDays} from '../lib'
1313

1414
export class ScheduleRow extends React.PureComponent {
1515
props: {
16-
schedule: SingleBuildingScheduleType,
16+
set: SingleBuildingScheduleType,
1717
isActive: boolean,
1818
now: moment,
1919
}
2020

2121
render() {
22-
const {schedule, isActive, now} = this.props
22+
const {set, isActive, now} = this.props
2323
return (
2424
<Cell
2525
cellStyle="RightDetail"
26-
title={summarizeDays(schedule.days)}
26+
title={summarizeDays(set.days)}
2727
titleTextStyle={isActive ? styles.bold : null}
28-
detail={formatBuildingTimes(schedule, now)}
28+
detail={formatBuildingTimes(set, now)}
2929
detailTextStyle={isActive ? styles.bold : null}
3030
/>
3131
)

source/views/building-hours/detail/schedule-table.android.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ export class ScheduleTable extends React.PureComponent {
2424

2525
return (
2626
<View>
27-
{schedules.map(set =>
27+
{schedules.map(schedule =>
2828
<Card
29-
key={set.title}
29+
key={schedule.title}
3030
style={styles.scheduleContainer}
31-
header={set.title}
32-
footer={set.notes}
31+
header={schedule.title}
32+
footer={schedule.notes}
3333
>
34-
{set.hours.map((schedule, i) =>
34+
{schedule.hours.map((set, i) =>
3535
<ScheduleRow
3636
key={i}
3737
now={now}
38-
schedule={schedule}
38+
set={set}
3939
isActive={
40-
set.isPhysicallyOpen !== false &&
41-
schedule.days.includes(dayOfWeek) &&
42-
isScheduleOpenAtMoment(schedule, this.state.now)
40+
schedule.isPhysicallyOpen !== false &&
41+
set.days.includes(dayOfWeek) &&
42+
isBuildingOpenAtMoment(set, this.state.now)
4343
}
4444
/>,
4545
)}

source/views/building-hours/detail/schedule-table.ios.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,34 @@ export class ScheduleTable extends React.PureComponent {
2323

2424
return (
2525
<TableView>
26-
<Section>
27-
<Cell
28-
accessory="DisclosureIndicator"
29-
title="Suggest an Edit"
30-
onPress={onProblemReport}
31-
/>
32-
</Section>
33-
34-
{schedules.map(set =>
26+
{schedules.map(schedule =>
3527
<Section
36-
key={set.title}
37-
header={set.title.toUpperCase()}
38-
footer={set.notes}
28+
key={schedule.title}
29+
header={schedule.title.toUpperCase()}
30+
footer={schedule.notes}
3931
>
40-
{set.hours.map((schedule, i) =>
32+
{schedule.hours.map((set, i) =>
4133
<ScheduleRow
4234
key={i}
4335
now={now}
44-
schedule={schedule}
36+
set={set}
4537
isActive={
46-
set.isPhysicallyOpen !== false &&
47-
schedule.days.includes(dayOfWeek) &&
48-
isScheduleOpenAtMoment(schedule, now)
38+
schedule.isPhysicallyOpen !== false &&
39+
set.days.includes(dayOfWeek) &&
40+
isBuildingOpenAtMoment(set, now)
4941
}
5042
/>,
5143
)}
5244
</Section>,
5345
)}
46+
47+
<Section>
48+
<Cell
49+
accessory="DisclosureIndicator"
50+
title="Suggest an Edit"
51+
onPress={onProblemReport}
52+
/>
53+
</Section>
5454
</TableView>
5555
)
5656
}

source/views/components/__tests__/cell-toggle.test.js renamed to source/views/components/cells/__tests__/toggle.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import React from 'react'
55
import {shallow} from 'enzyme'
66

7-
import {CellToggle} from '../cell-toggle'
7+
import {CellToggle} from '../toggle'
88
import noop from 'lodash/noop'
99

1010
test('renders', () => {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// @flow
2+
3+
import React from 'react'
4+
import {StyleSheet, Text} from 'react-native'
5+
import {Cell} from 'react-native-tableview-simple'
6+
import * as c from '../../components/colors'
7+
8+
const styles = StyleSheet.create({
9+
title: {
10+
textAlign: 'left',
11+
},
12+
active: {
13+
color: c.infoBlue,
14+
},
15+
disabled: {
16+
color: c.iosDisabledText,
17+
},
18+
})
19+
20+
export function ButtonCell({
21+
indeterminate,
22+
disabled,
23+
onPress,
24+
title,
25+
}: {
26+
indeterminate?: boolean,
27+
disabled?: boolean,
28+
onPress: () => any,
29+
title: string,
30+
}) {
31+
return (
32+
<Cell
33+
titleTextStyle={styles.title}
34+
isDisabled={indeterminate || disabled}
35+
onPress={onPress}
36+
title={
37+
<Text
38+
style={[
39+
styles.text,
40+
indeterminate || disabled ? styles.disabled : styles.active,
41+
]}
42+
>
43+
{title}
44+
</Text>
45+
}
46+
/>
47+
)
48+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @flow
2+
3+
import React from 'react'
4+
import {StyleSheet, Alert} from 'react-native'
5+
import {Cell} from 'react-native-tableview-simple'
6+
import * as c from '../colors'
7+
8+
const deleteStyles = StyleSheet.create({
9+
text: {textAlign: 'center', color: c.red},
10+
})
11+
12+
export const DeleteButtonCell = ({
13+
title,
14+
skipConfirm = false,
15+
onPress,
16+
}: {
17+
title: string,
18+
skipConfirm?: boolean,
19+
onPress?: () => any,
20+
}) => {
21+
const onPressCallback = onPress ? onPress : () => {}
22+
23+
const callback = !skipConfirm
24+
? () =>
25+
Alert.alert(title, 'Are you sure you want to delete this?', [
26+
{text: 'Cancel', onPress: () => {}, style: 'cancel'},
27+
{text: 'Delete', onPress: onPressCallback, style: 'destructive'},
28+
])
29+
: onPressCallback
30+
31+
return (
32+
<Cell title={title} titleTextStyle={deleteStyles.text} onPress={callback} />
33+
)
34+
}
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+
}

0 commit comments

Comments
 (0)