Skip to content

Commit

Permalink
style: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermelcdev committed Jul 27, 2022
1 parent 6a4fe2d commit ecdd5df
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 124 deletions.
27 changes: 11 additions & 16 deletions src/DateTimePickerModal.android.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useRef, useState, memo } from "react";
import PropTypes from "prop-types";
import DateTimePicker from "@react-native-community/datetimepicker";
import React, { useEffect, useRef, useState, memo } from 'react';
import PropTypes from 'prop-types';
import DateTimePicker from '@react-native-community/datetimepicker';

// Memo workaround for https://github.com/react-native-community/datetimepicker/issues/54
const areEqual = (prevProps, nextProps) => {
Expand All @@ -17,7 +17,7 @@ const DateTimePickerModal = memo(

useEffect(() => {
if (isVisible && currentMode === null) {
setCurrentMode(mode === "time" ? "time" : "date");
setCurrentMode(mode === 'time' ? 'time' : 'date');
} else if (!isVisible) {
setCurrentMode(null);
}
Expand All @@ -26,18 +26,18 @@ const DateTimePickerModal = memo(
if (!isVisible || !currentMode) return null;

const handleChange = (event, date) => {
if (event.type === "dismissed") {
if (event.type === 'dismissed') {
onCancel();
onHide(false);
return;
}
let nextDate = date;
if (mode === "datetime") {
if (currentMode === "date") {
setCurrentMode("time");
if (mode === 'datetime') {
if (currentMode === 'date') {
setCurrentMode('time');
currentDateRef.current = new Date(date);
return;
} else if (currentMode === "time") {
} else if (currentMode === 'time') {
const year = currentDateRef.current.getFullYear();
const month = currentDateRef.current.getMonth();
const day = currentDateRef.current.getDate();
Expand All @@ -51,15 +51,10 @@ const DateTimePickerModal = memo(
};

return (
<DateTimePicker
{...otherProps}
mode={currentMode}
value={date}
onChange={handleChange}
/>
<DateTimePicker {...otherProps} mode={currentMode} value={date} onChange={handleChange} />
);
},
areEqual
areEqual,
);

DateTimePickerModal.propTypes = {
Expand Down
108 changes: 36 additions & 72 deletions src/DateTimePickerModal.ios.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import React from "react";
import PropTypes from "prop-types";
import {
StyleSheet,
Text,
TouchableHighlight,
View,
Appearance,
} from "react-native";
import DateTimePicker from "@react-native-community/datetimepicker";
import Modal from "./Modal";
import { isIphoneX } from "./utils";
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TouchableHighlight, View, Appearance } from 'react-native';
import DateTimePicker from '@react-native-community/datetimepicker';
import Modal from './Modal';
import { isIphoneX } from './utils';

export const BACKGROUND_COLOR_LIGHT = "white";
export const BACKGROUND_COLOR_DARK = "#0E0E0E";
export const BORDER_COLOR = "#d5d5d5";
export const BORDER_COLOR_DARK = "#272729";
export const BACKGROUND_COLOR_LIGHT = 'white';
export const BACKGROUND_COLOR_DARK = '#0E0E0E';
export const BORDER_COLOR = '#d5d5d5';
export const BORDER_COLOR_DARK = '#272729';
export const BORDER_RADIUS = 13;
export const BUTTON_FONT_WEIGHT = "normal";
export const BUTTON_FONT_COLOR = "#007ff9";
export const BUTTON_FONT_WEIGHT = 'normal';
export const BUTTON_FONT_COLOR = '#007ff9';
export const BUTTON_FONT_SIZE = 20;
export const HIGHLIGHT_COLOR_DARK = "#444444";
export const HIGHLIGHT_COLOR_LIGHT = "#ebebeb";
export const HIGHLIGHT_COLOR_DARK = '#444444';
export const HIGHLIGHT_COLOR_LIGHT = '#ebebeb';

export class DateTimePickerModal extends React.PureComponent {
static propTypes = {
Expand Down Expand Up @@ -50,8 +44,8 @@ export class DateTimePickerModal extends React.PureComponent {
};

static defaultProps = {
cancelTextIOS: "Cancel",
confirmTextIOS: "Confirm",
cancelTextIOS: 'Cancel',
confirmTextIOS: 'Confirm',
modalPropsIOS: {},
date: new Date(),
isDarkModeEnabled: undefined,
Expand Down Expand Up @@ -126,12 +120,10 @@ export class DateTimePickerModal extends React.PureComponent {
buttonTextColorIOS,
...otherProps
} = this.props;
const isAppearanceModuleAvailable = !!(
Appearance && Appearance.getColorScheme
);
const isAppearanceModuleAvailable = !!(Appearance && Appearance.getColorScheme);
const _isDarkModeEnabled =
isDarkModeEnabled === undefined && isAppearanceModuleAvailable
? Appearance.getColorScheme() === "dark"
? Appearance.getColorScheme() === 'dark'
: isDarkModeEnabled || false;

const ConfirmButtonComponent = customConfirmButtonIOS || ConfirmButton;
Expand All @@ -152,27 +144,17 @@ export class DateTimePickerModal extends React.PureComponent {
backdropStyle={backdropStyleIOS}
{...modalPropsIOS}
>
<View
style={[
pickerStyles.container,
themedContainerStyle,
pickerContainerStyleIOS,
]}
>
<View style={[pickerStyles.container, themedContainerStyle, pickerContainerStyleIOS]}>
{HeaderComponent && <HeaderComponent />}
{!HeaderComponent && display === "inline" && (
<View style={pickerStyles.headerFiller} />
)}
{!HeaderComponent && display === 'inline' && <View style={pickerStyles.headerFiller} />}
<View
style={[
display === "inline"
? pickerStyles.pickerInline
: pickerStyles.pickerSpinner,
display === 'inline' ? pickerStyles.pickerInline : pickerStyles.pickerSpinner,
pickerStyleIOS,
]}
>
<PickerComponent
display={display || "spinner"}
display={display || 'spinner'}
{...otherProps}
value={this.state.currentDate}
onChange={this.handleChange}
Expand Down Expand Up @@ -200,13 +182,13 @@ export class DateTimePickerModal extends React.PureComponent {

const pickerStyles = StyleSheet.create({
modal: {
justifyContent: "flex-end",
justifyContent: 'flex-end',
margin: 10,
},
container: {
borderRadius: BORDER_RADIUS,
marginBottom: 8,
overflow: "hidden",
overflow: 'hidden',
},
pickerSpinner: {
marginBottom: 8,
Expand Down Expand Up @@ -235,9 +217,7 @@ export const ConfirmButton = ({
? confirmButtonStyles.buttonDark
: confirmButtonStyles.buttonLight;

const underlayColor = isDarkModeEnabled
? HIGHLIGHT_COLOR_DARK
: HIGHLIGHT_COLOR_LIGHT;
const underlayColor = isDarkModeEnabled ? HIGHLIGHT_COLOR_DARK : HIGHLIGHT_COLOR_LIGHT;
return (
<TouchableHighlight
testID={confirmButtonTestID}
Expand All @@ -248,24 +228,17 @@ export const ConfirmButton = ({
accessibilityRole="button"
accessibilityLabel={label}
>
<Text
style={[
style.text,
buttonTextColorIOS && { color: buttonTextColorIOS },
]}
>
{label}
</Text>
<Text style={[style.text, buttonTextColorIOS && { color: buttonTextColorIOS }]}>{label}</Text>
</TouchableHighlight>
);
};

export const confirmButtonStyles = StyleSheet.create({
button: {
borderTopWidth: StyleSheet.hairlineWidth,
backgroundColor: "transparent",
backgroundColor: 'transparent',
height: 57,
justifyContent: "center",
justifyContent: 'center',
},
buttonLight: {
borderColor: BORDER_COLOR,
Expand All @@ -274,11 +247,11 @@ export const confirmButtonStyles = StyleSheet.create({
borderColor: BORDER_COLOR_DARK,
},
text: {
textAlign: "center",
textAlign: 'center',
color: BUTTON_FONT_COLOR,
fontSize: BUTTON_FONT_SIZE,
fontWeight: BUTTON_FONT_WEIGHT,
backgroundColor: "transparent",
backgroundColor: 'transparent',
},
});

Expand All @@ -293,9 +266,7 @@ export const CancelButton = ({
const themedButtonStyle = isDarkModeEnabled
? cancelButtonStyles.buttonDark
: cancelButtonStyles.buttonLight;
const underlayColor = isDarkModeEnabled
? HIGHLIGHT_COLOR_DARK
: HIGHLIGHT_COLOR_LIGHT;
const underlayColor = isDarkModeEnabled ? HIGHLIGHT_COLOR_DARK : HIGHLIGHT_COLOR_LIGHT;
return (
<TouchableHighlight
testID={cancelButtonTestID}
Expand All @@ -306,14 +277,7 @@ export const CancelButton = ({
accessibilityRole="button"
accessibilityLabel={label}
>
<Text
style={[
style.text,
buttonTextColorIOS && { color: buttonTextColorIOS },
]}
>
{label}
</Text>
<Text style={[style.text, buttonTextColorIOS && { color: buttonTextColorIOS }]}>{label}</Text>
</TouchableHighlight>
);
};
Expand All @@ -323,7 +287,7 @@ export const cancelButtonStyles = StyleSheet.create({
borderRadius: BORDER_RADIUS,
height: 57,
marginBottom: isIphoneX() ? 20 : 0,
justifyContent: "center",
justifyContent: 'center',
},
buttonLight: {
backgroundColor: BACKGROUND_COLOR_LIGHT,
Expand All @@ -333,10 +297,10 @@ export const cancelButtonStyles = StyleSheet.create({
},
text: {
padding: 10,
textAlign: "center",
textAlign: 'center',
color: BUTTON_FONT_COLOR,
fontSize: BUTTON_FONT_SIZE,
fontWeight: "600",
backgroundColor: "transparent",
fontWeight: '600',
backgroundColor: 'transparent',
},
});
4 changes: 2 additions & 2 deletions src/DateTimePickerModal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Platform } from "react-native";
import React from 'react';
import { Platform } from 'react-native';

export function DateTimePickerModal() {
React.useEffect(() => {
Expand Down
Loading

0 comments on commit ecdd5df

Please sign in to comment.