ant-design / ant-design-mobile-rn

Ant Design for React Native
https://rn.mobile.ant.design/
MIT License
3.09k stars 611 forks source link

[Bug] DatePicker的defaultValue和defaultDate字段都没有生效 #1351

Closed inkCrazy closed 4 months ago

inkCrazy commented 4 months ago

💬 Before You Start

🙋 Description/Step to reproduce

<DatePicker
                value={this.state.customDate}
                // defaultValue={dayjs().subtract(2, 'day').toDate()}
                defaultValue={new Date()}
                minDate={new Date('2023-01-01')}
                maxDate={dayjs().subtract(2, 'day').toDate()} //最小是前天
                onOk={this.endTimeConfirm}
                onDismiss={this.endTimeCancel}
                precision="day"
                onChange={this.endTimeonChange}
                format="YYYY-MM-DD">
                <List.Item arrow="horizontal">
                  <View style={styles.datePickerListTitle}>
                    <Text style={styles.importFlag}>*</Text>
                    <Text style={styles.title}>自定义时间</Text>
                  </View>
                </List.Item>
              </DatePicker>

image

🔴 Version

9.8.1

💻 Environment

iOS, Android

⚫️ Output of npx react-native info

System: OS: macOS 14.5 CPU: (10) arm64 Apple M2 Pro Memory: 91.73 MB / 16.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 20.0.0 path: /usr/local/bin/node Yarn: version: 1.22.19 path: /opt/homebrew/bin/yarn npm: version: 9.8.1 path: /opt/homebrew/bin/npm Watchman: version: 2024.01.22.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.14.3 path: /Users/inkcrazy/.rvm/gems/ruby-3.0.0/bin/pod SDKs: iOS SDK: Platforms:

Additional comments

No response

inkCrazy commented 4 months ago

没问题了,maxDate限制了defaultValue,没注意,同时设置了value值是undefined或者null,会导致defaultValue失效,然后value就是最小日期