Skip to content

Commit

Permalink
DatePicker Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Srishti Sharma authored and Srishti Sharma committed Jul 9, 2019
1 parent 1ca2d20 commit f921041
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
14 changes: 8 additions & 6 deletions src/basic/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import { connectStyle } from 'native-base-shoutem-theme';

import variable from '../theme/variables/platform';
import { PLATFORM } from '../theme/variables/commonColor';

import computeProps from '../utils/computeProps';
import mapPropsToStyleNames from '../utils/mapPropsToStyleNames';

Expand Down Expand Up @@ -58,19 +60,19 @@ class Button extends Component {
? this.context.theme['@@shoutem.theme/themeStyle'].variables
: variable;
const children =
Platform.OS === 'ios'
Platform.OS === PLATFORM.IOS
? this.props.children
: React.Children.map(this.props.children, child =>
child && child.type === Text
? React.cloneElement(child, {
uppercase: variables.buttonUppercaseAndroidText,
...child.props
})
uppercase: variables.buttonUppercaseAndroidText,
...child.props
})
: child
);
if (
Platform.OS === 'ios' ||
Platform.OS === 'web' ||
Platform.OS === PLATFORM.IOS ||
Platform.OS === PLATFORM.WEB ||
variables.androidRipple === false ||
Platform.Version < 21
) {
Expand Down
54 changes: 37 additions & 17 deletions src/basic/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from 'react-native';

import variable from '../theme/variables/platform';
import { PLATFORM } from '../theme/variables/commonColor';

import { Text } from './Text';

Expand Down Expand Up @@ -35,7 +36,7 @@ export class DatePicker extends React.Component {
}

showDatePicker = () => {
if (Platform.OS === 'android') {
if (Platform.OS === PLATFORM.ANDROID) {
this.openAndroidDatePicker();
} else {
this.setState({ modalVisible: true });
Expand Down Expand Up @@ -71,40 +72,59 @@ export class DatePicker extends React.Component {
}

render() {
const {
androidMode,
animationType,
disabled,
formatChosenDate,
locale,
maximumDate,
minimumDate,
modalTransparent,
onDateChange,
placeHolderText,
placeHolderTextStyle,
textStyle,
timeZoneOffsetInMinutes
} = this.props;

const variables = this.context.theme
? this.context.theme['@@shoutem.theme/themeStyle'].variables
: variable;

return (
<View>
<View>
<Text
onPress={() =>
!this.props.disabled ? this.showDatePicker() : undefined
}
onPress={() => (!disabled ? this.showDatePicker() : undefined)}
style={[
{ padding: 10, color: variables.datePickerTextColor },
this.state.chosenDate
? this.props.textStyle
: this.props.placeHolderTextStyle
{
padding: variables.datePickerPadding,
color: variables.datePickerTextColor
},
this.state.chosenDate ? textStyle : placeHolderTextStyle
]}
>
{this.state.chosenDate
? this.formatChosenDate(this.state.chosenDate)
: this.props.placeHolderText
? this.props.placeHolderText
: placeHolderText
? placeHolderText
: 'Select Date'}
</Text>
<View>
<Modal
supportedOrientations={['portrait', 'landscape']}
animationType={this.props.animationType}
transparent={this.props.modalTransparent} // from api
animationType={animationType}
transparent={modalTransparent} // from api
visible={this.state.modalVisible}
onRequestClose={() => {}}
>
<Text
onPress={() => this.setState({ modalVisible: false })}
style={{ backgroundColor: variables.datePickerBg, flex: 1 }}
style={{
backgroundColor: variables.datePickerBg,
flex: variables.datePickerFlex
}}
/>
<DatePickerIOS
date={
Expand All @@ -113,11 +133,11 @@ export class DatePicker extends React.Component {
: this.state.defaultDate
}
onDateChange={date => this.setDate(date)}
minimumDate={this.props.minimumDate}
maximumDate={this.props.maximumDate}
minimumDate={minimumDate}
maximumDate={maximumDate}
mode="date"
locale={this.props.locale}
timeZoneOffsetInMinutes={this.props.timeZoneOffsetInMinutes}
locale={locale}
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes}
/>
</Modal>
</View>
Expand Down
4 changes: 3 additions & 1 deletion src/theme/variables/commonColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import color from 'color';
import { Platform, Dimensions, PixelRatio } from 'react-native';

export const PLATFORM = {
ANDROID: 'android',
IOS: 'ios',
MATERIAL: 'material'
MATERIAL: 'material',
WEB: 'web'
};

const deviceHeight = Dimensions.get('window').height;
Expand Down
2 changes: 2 additions & 0 deletions src/theme/variables/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export default {
containerBgColor: '#fff',

// Date Picker
datePickerFlex: 1,
datePickerPadding: 10,
datePickerTextColor: '#000',
datePickerBg: 'transparent',

Expand Down

0 comments on commit f921041

Please sign in to comment.