react-native-date-picker icon indicating copy to clipboard operation
react-native-date-picker copied to clipboard

Android: Picker does not show correctly when the mode prop changes

Open phamhoaivu911 opened this issue 4 years ago • 5 comments

Describe the bug On Android, when the mode prop changes, the UI shows a blank space with only the separator.

Expected behavior When the mode prop changes, the UI should show the correct picker for that mode.

Screenshots In the video below, the switch toggles the mode prop between "date" and "datetime". The initial value for mode is "date", which shows correctly. But when the mode prop is changed to "datetime", it shows blank.

https://user-images.githubusercontent.com/4929170/138826099-26e774f8-e0e3-44bc-86e4-3a4a00229435.mp4

To Reproduce Add example code that reproduces the behavior.

export default class App extends Component {

  state = { date: new Date(), mode:  "date"}
  
  render = () => 
  <View>
    <Button title="Toggle" onPress={() => {
      if (this.state.mode === "date") {
        this.setState({ mode: "datetime" })
      } else {
        this.setState({ mode: "date" })
      }
    }} />
    <DatePicker
      mode={this.state.mode}
      date={this.state.date}
      onDateChange={date => this.setState({ date })}
    />
  <View>

}

Smartphone (please complete the following information):

  • OS: Android
  • React Native version: 0.63.4
  • react-native-date-picker version: 4.1.1

phamhoaivu911 avatar Oct 26 '21 07:10 phamhoaivu911

Can you see any error in the android logs (LogCat) when this happens?

henninghall avatar Dec 20 '21 18:12 henninghall

@phamhoaivu911 how did you show the value on screen? i'm getting error

jotilohana avatar Apr 16 '22 15:04 jotilohana

Hi @jotilohana , our current workaround is adding the key prop to force the picker to re-render

<DatePicker
  key={Platform.os === "android" ? this.state.mode : undefined}
  mode={this.state.mode}
  date={this.state.date}
  onDateChange={date => this.setState({ date })}
/>

Hope this helps

phamhoaivu911 avatar Apr 18 '22 05:04 phamhoaivu911

@phamhoaivu911 I'm getting error "Objects are not valid as React child...." value is being consoled but doesn't appear on application screen

jotilohana avatar Apr 18 '22 08:04 jotilohana

Try using textColor property and set it to black explicitly, that worked on Pixel 6 Pro.

matijagrcic avatar Sep 01 '22 08:09 matijagrcic

Try using textColor property and set it to black explicitly, that worked on Pixel 6 Pro.

thanks it works

cybexai avatar Nov 03 '22 06:11 cybexai

Try using textColor property and set it to black explicitly, that worked on Pixel 6 Pro.

This fixes the issue if the phone is using dark mode, since the datepicker seems to use a white font when the phone is in dark mode, making it appear as if the datepicker is blank.

nicktiberi avatar Nov 07 '22 16:11 nicktiberi