Skip to content

Commit a5e67d2

Browse files
authored
Merge pull request #1629 from StoDevX/datepicker
Bring in the datepicker dependency
2 parents aaa2c59 + 7eb0062 commit a5e67d2

File tree

9 files changed

+622
-84
lines changed

9 files changed

+622
-84
lines changed

package-lock.json

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
"react-native-calendar-events": "1.4.1",
7070
"react-native-communications": "2.2.1",
7171
"react-native-custom-tabs": "0.1.7",
72-
"react-native-datepicker": "1.6.0",
7372
"react-native-device-info": "0.11.0",
7473
"react-native-google-analytics-bridge": "5.3.3",
7574
"react-native-keychain": "2.0.0-rc",

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
/**
2-
* @flow
3-
*
4-
* <ScheduleTable/> renders the table of schedules.
5-
*/
1+
// @flow
62

73
import React from 'react'
84
import {View, StyleSheet} from 'react-native'
@@ -47,6 +43,7 @@ export class ScheduleTable extends React.PureComponent {
4743
)}
4844
</Card>,
4945
)}
46+
5047
<Card style={styles.scheduleContainer}>
5148
<ButtonCell title="Suggest an Edit" onPress={onProblemReport} />
5249
</Card>

source/views/building-hours/report/editor.js

Lines changed: 25 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {Row} from '../../components/layout'
1414
import type {TopLevelViewPropsType} from '../../types'
1515
import {parseHours, blankSchedule} from '../lib'
1616
import * as c from '../../components/colors'
17-
import DatePicker from 'react-native-datepicker'
17+
import {DatePicker} from '../../components/datepicker'
1818
import {Touchable} from '../../components/touchable'
1919
import {DeleteButtonCell} from '../../components/cells/delete-button'
2020
import {CellToggle} from '../../components/cells/toggle'
@@ -114,14 +114,13 @@ class WeekTogglesIOS extends React.PureComponent {
114114
const allDays = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
115115

116116
return (
117-
<Row justifyContent="center">
118-
{allDays.map((day, i) =>
117+
<Row justifyContent="center" alignItems="stretch">
118+
{allDays.map(day =>
119119
<ToggleButton
120120
key={day}
121121
text={day}
122122
active={this.props.days.includes(day)}
123123
onPress={this.toggleDay}
124-
style={i === allDays.length - 1 && styles.finalCell}
125124
/>,
126125
)}
127126
</Row>
@@ -149,9 +148,7 @@ class WeekTogglesAndroid extends React.PureComponent {
149148
value={this.props.days.includes(day)}
150149
onChange={() => this.toggleDay(day)}
151150
/>
152-
{i === allDays.length - 1 && styles.finalCell
153-
? null
154-
: <ListSeparator force={true} />}
151+
{i === allDays.length - 1 ? null : <ListSeparator force={true} />}
155152
</View>,
156153
)}
157154
</View>
@@ -164,17 +161,16 @@ class ToggleButton extends React.PureComponent {
164161
active: boolean,
165162
text: string,
166163
onPress: (newState: string) => any,
167-
style?: any,
168164
}
169165

170166
onPress = () => this.props.onPress(this.props.text)
171167

172168
render() {
173-
const {text, style, active} = this.props
169+
const {text, active} = this.props
174170
return (
175171
<Touchable
176172
highlight={false}
177-
containerStyle={[style, styles.dayWrapper, active && styles.activeDay]}
173+
containerStyle={[styles.dayWrapper, active && styles.activeDay]}
178174
onPress={this.onPress}
179175
>
180176
<Text style={[styles.dayText, active && styles.activeDayText]}>
@@ -191,32 +187,40 @@ class DatePickerCell extends React.PureComponent {
191187
props: {
192188
date: moment,
193189
title: string,
194-
onChange?: (date: moment) => any,
195-
_ref?: (ref: any) => any,
190+
onChange: (date: moment) => any,
196191
}
197192

198193
_picker: any
199194
openPicker = () => this._picker.onPressDate()
200195

201-
getRef = (ref: any) => {
202-
this._picker = ref
203-
this.props._ref && this.props._ref(ref)
204-
}
196+
getRef = (ref: any) => (this._picker = ref)
205197

206198
onChange = (newDate: moment) => {
207-
console.log(newDate)
208-
this.props.onChange && this.props.onChange(newDate)
199+
const oldMoment = moment()
200+
201+
oldMoment.hours(newDate.hours())
202+
oldMoment.minutes(newDate.minutes())
203+
204+
this.props.onChange(oldMoment)
209205
}
210206

211207
render() {
212-
const {date, title} = this.props
208+
const format = 'h:mm A'
209+
213210
const accessory = (
214-
<Date _ref={this.getRef} date={date.toDate()} onChange={this.onChange} />
211+
<DatePicker
212+
ref={this.getRef}
213+
initialDate={this.props.date}
214+
minuteInterval={5}
215+
mode="time"
216+
format={format}
217+
onDateChange={this.onChange}
218+
/>
215219
)
216220

217221
return (
218222
<Cell
219-
title={title}
223+
title={this.props.title}
220224
cellStyle="RightDetail"
221225
cellAccessoryView={accessory}
222226
onPress={this.openPicker}
@@ -225,51 +229,13 @@ class DatePickerCell extends React.PureComponent {
225229
}
226230
}
227231

228-
const Date = ({date, onChange, _ref}) => {
229-
const format = 'h:mma'
230-
231-
const callback = (newDateString: string) => {
232-
const oldMoment = moment(date)
233-
const newMoment = moment(newDateString, format)
234-
235-
oldMoment.hours(newMoment.hours())
236-
oldMoment.minutes(newMoment.minutes())
237-
238-
onChange(oldMoment)
239-
}
240-
241-
return (
242-
<DatePicker
243-
ref={_ref}
244-
date={date}
245-
style={styles.datePicker}
246-
mode="time"
247-
format={format}
248-
is24Hour={false}
249-
confirmBtnText="Confirm"
250-
cancelBtnText="Cancel"
251-
showIcon={false}
252-
onDateChange={callback}
253-
customStyles={{
254-
dateInput: styles.datePickerInput,
255-
dateText: styles.datePickerText,
256-
}}
257-
/>
258-
)
259-
}
260-
261232
const styles = StyleSheet.create({
262233
dayWrapper: {
263234
flex: 1,
264235
alignItems: 'center',
265236
paddingVertical: 10,
266237
paddingHorizontal: 2,
267238
backgroundColor: c.white,
268-
//borderRightWidth: StyleSheet.hairlineWidth,
269-
//borderRightColor: c.iosSeparator,
270-
},
271-
finalCell: {
272-
borderRightWidth: 0,
273239
},
274240
activeDay: {
275241
backgroundColor: c.brickRed,
@@ -280,15 +246,4 @@ const styles = StyleSheet.create({
280246
activeDayText: {
281247
color: c.white,
282248
},
283-
datePicker: {
284-
width: null,
285-
},
286-
datePickerInput: {
287-
flex: 0,
288-
borderWidth: 0,
289-
},
290-
datePickerText: {
291-
color: c.iosDisabledText,
292-
fontSize: 16,
293-
},
294249
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 鲜果FE
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)