Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: improved android picker + remove variants #781

Merged
merged 52 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a96c054
add file
henninghall Feb 12, 2024
d19613b
change package name
henninghall Feb 12, 2024
5c298e1
remove widget
henninghall Feb 12, 2024
f8b8fb5
direct access variables to functions
henninghall Feb 12, 2024
b6e47db
rest of errors
henninghall Feb 12, 2024
a53cb19
builds but styles are not resolved
henninghall Feb 12, 2024
759118b
replace with newer number picker
henninghall Feb 12, 2024
ca9a145
Merge branch 'master' into number-picker-android-source
henninghall Mar 4, 2024
0ea8b5c
render non material version
henninghall Mar 11, 2024
3940b31
selector wheels
henninghall Mar 11, 2024
b14d20c
material
henninghall Mar 11, 2024
1f3570c
restore material
henninghall Mar 11, 2024
328e2b2
visible divider
henninghall Mar 11, 2024
2945e01
nice divider
henninghall Mar 11, 2024
32eca84
temp
henninghall Mar 11, 2024
42608c4
script
henninghall Mar 11, 2024
b247223
cleanup
henninghall Mar 11, 2024
3b3ef0f
wip
henninghall Mar 11, 2024
0707a4b
wip
henninghall Mar 11, 2024
e54fd25
wip
henninghall Mar 11, 2024
f56c1a7
wip
henninghall Mar 11, 2024
a7a4d7e
wip
henninghall Mar 11, 2024
fedf504
update patch
henninghall Mar 11, 2024
f41483e
cleanup
henninghall Mar 11, 2024
f1e3bcf
back
henninghall Mar 11, 2024
43fa3a6
cleanup
henninghall Mar 11, 2024
8dd325e
cleanup
henninghall Mar 11, 2024
ff7c904
remove variant
henninghall Mar 11, 2024
839de2c
script + remove things
henninghall Mar 11, 2024
7352953
patching
henninghall Mar 11, 2024
c2ea1bb
cleanup
henninghall Mar 11, 2024
6ace0c8
wip
henninghall Mar 11, 2024
02095bb
re add
henninghall Mar 11, 2024
9bc26ca
remove fade to color
henninghall Mar 11, 2024
3a9b877
inflating
henninghall Mar 11, 2024
84d48a6
remove variant prop
henninghall Mar 12, 2024
066f3dd
remove text color prop
henninghall Mar 18, 2024
5ff56ab
Merge branch 'master' into dup-res
henninghall Mar 18, 2024
28545da
remove props
henninghall Mar 18, 2024
57fafca
divider color
henninghall Mar 18, 2024
a423528
android modal button colors
henninghall Mar 18, 2024
d94870a
typescript
henninghall Mar 18, 2024
27fdd8a
update readme
henninghall Mar 18, 2024
4efa4d7
update patch divider tint
henninghall Mar 18, 2024
cf09f75
fabric prop
henninghall Mar 18, 2024
5029b6d
remove style
henninghall Mar 18, 2024
3c309be
reset minimal
henninghall Mar 18, 2024
2574055
swipe distance
henninghall Mar 18, 2024
8588ac5
swipe wheel 2
henninghall Mar 23, 2024
ca6cfed
ios swipe
henninghall Mar 23, 2024
ce7e12f
test fixes
henninghall Mar 23, 2024
d7ae7cb
test fix
henninghall Mar 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .maestro/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tags:
env:
PROP: locale
VALUE: vi-VN
- runFlow: utils/swipe-wheel-1.yml
- runFlow: utils/swipe-wheel-1-down-ios.yml
- assertVisible:
text: '2000-01-01 01:00:00'

Expand Down
2 changes: 1 addition & 1 deletion .maestro/timezone-offset-in-minutes-daylight-saving.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ tags:
VALUE: 180
- runFlow: utils/swipe-wheel-3.yml
- assertVisible: '2000-06-01 00:01:00'
- assertVisible: 'Thu Jun 1101 AM '
- assertVisible: 'Thu Jun 1 1 01 AM '
4 changes: 2 additions & 2 deletions .maestro/timezone-offset-in-minutes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tags:
VALUE: 180
- runFlow: utils/swipe-wheel-3.yml
- assertVisible: '2000-01-01 00:01:00'
- assertVisible: 'Sat Jan 1201 AM '
- assertVisible: 'Sat Jan 1 2 01 AM '

- runFlow: utils/reset.yml

Expand All @@ -51,7 +51,7 @@ tags:
VALUE: -180
- runFlow: utils/swipe-wheel-3.yml
- assertVisible: '2000-01-01 00:01:00'
- assertVisible: 'Fri Dec 31801 PM '
- assertVisible: 'Fri Dec 31 8 01 PM '
- runFlow: utils/reset.yml

# test: timezoneOffsetInMinutes combined with maximumDate/minimumDate in another timezone than current device.
Expand Down
5 changes: 5 additions & 0 deletions .maestro/utils/swipe-wheel-1-down-ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
appId: com.rn071
---
- swipe:
start: 25%, 40%
end: 25%, 35%
2 changes: 1 addition & 1 deletion .maestro/utils/swipe-wheel-1-down.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ appId: com.rn071
---
- swipe:
start: 25%, 40%
end: 25%, 35%
end: 25%, 32%
4 changes: 2 additions & 2 deletions .maestro/utils/swipe-wheel-1-up.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appId: com.rn071
---
- swipe:
start: 38%, 30%
end: 38%, 35%
start: 38%, 32%
end: 38%, 40%
4 changes: 2 additions & 2 deletions .maestro/utils/swipe-wheel-2-up.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appId: com.rn071
---
- swipe:
start: 50%, 30%
end: 50%, 35%
start: 53%, 32%
end: 53%, 40%
4 changes: 2 additions & 2 deletions .maestro/utils/swipe-wheel-2.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appId: com.rn071
---
- swipe:
start: 50%, 40%
end: 50%, 35%
start: 53%, 40%
end: 53%, 32%
4 changes: 2 additions & 2 deletions .maestro/utils/swipe-wheel-3-up.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appId: com.rn071
---
- swipe:
start: 65%, 30%
end: 65%, 35%
start: 65%, 32%
end: 65%, 40%
4 changes: 2 additions & 2 deletions .maestro/utils/swipe-wheel-3.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appId: com.rn071
---
- swipe:
start: 63%, 40%
end: 63%, 35%
start: 65%, 40%
end: 65%, 32%
2 changes: 1 addition & 1 deletion .maestro/utils/swipe-wheel-4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ appId: com.rn071
---
- swipe:
start: 75%, 40%
end: 75%, 35%
end: 75%, 32%
66 changes: 4 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,12 @@ export default () => {
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `date` | The currently selected date. |
| `onDateChange` | Date change handler ( Inline only ) |
| `fadeToColor` | Android picker is fading towards this background color. {color, 'none'} |
| `maximumDate` | Maximum selectable date. <br/> Example: `new Date("2021-12-31")` |
| `minimumDate` | Minimum selectable date. <br/> Example: `new Date("2021-01-01")` |
| `androidVariant` | Choose from 2 android style variants. `"iosClone"`, `"nativeAndroid"` | | <img src="docs/datetime-mode-android.png" alt="Datepicker ios clone variant" height="120px" /><img src="docs/react-native-date-picker-android.png" alt="Datepicker android native variant"/> |
| `minuteInterval` | The interval at which minutes can be selected. | <img src="docs/minute-interval-ios.png" alt="Date picker minute interval IOS" height="120px" /> | <img src="docs/minute-interval-android.png" alt="Date picker minute interval Android" height="120px" /> |
| `mode` | The date picker mode. `"datetime"`, `"date"`, `"time"` | <img src="docs/datetime-mode-ios.png" alt="React native date time picker" height="120px" /><img src="docs/date-mode-ios.png" alt="React native datepicker" height="120px" /><img src="docs/time-mode-ios.png" alt="React native time picker" height="120px" /> | <img src="docs/datetime-mode-android.png" alt="react native date time picker android" height="120px" /><img src="docs/date-mode-android.png" alt="react native datepicker android" height="120px" /><img src="docs/time-mode-android.png" alt="react native time picker android" height="120px" /> |
| `locale` | The locale for the date picker. Changes language, date order and am/pm preferences. Value needs to be a <a title="react native datepicker locale id" href="https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html">Locale ID.</a> | <img src="docs/locale-ios.png" alt="React Native Date picker locale language ios" height="120px" /> | <img src="docs/locale-android.png" alt="React Native Date picker locale language android" height="120px" /> |
| `textColor` | Changes the text color. ⚠ Colors other than black (#000000) or white (#ffffff) will replace the "Today" string with a date on iOS 13 or higher. | <img src="docs/colors-ios.png" alt="react native datepicker text color background color ios" height="120px" /> | <img src="docs/colors-android.png" alt="Text color background color android" height="120px" /> |
| `timeZoneOffsetInMinutes` | Timezone offset in minutes (default: device's timezone) |
| `dividerHeight` | Change the divider height (only supported for iosClone) |
| `is24hourSource` | Change how the 24h mode (am/pm) should be determined, by device settings or by locale. {'locale', 'device'} (android only, default: 'device') |
| `modal` | Boolean indicating if modal should be used. Default: `"false"`. When enabled, the other modal props needs to be used. <a href="#modal">See example</a>. |
| `open` | Modal only: Boolean indicating if modal should be open. |
Expand All @@ -154,37 +150,13 @@ export default () => {
| `confirmText` | Modal only: Confirm button text. |
| `cancelText` | Modal only: Cancel button text. |
| `theme` | Modal only: The theme of the modal. `"light"`, `"dark"`, `"auto"`. Defaults to `"auto"`. |
| `buttonColor` | Color of the confirm and cancel buttons. (android modal only) | | <img src="docs/button-colors.png" alt="date picker button colors on android" width="200px" /> |
| `dividerColor` | Color of the divider / separator. (android only) | | <img src="docs/divider-color.png" alt="react native date picker divider separator color" width="200px" /> |
| `onStateChange` | Spinner state change handler. Triggered on changes between "idle" and "spinning" state (Android inline only) |

## Additional android styling
## Font size

There are some additional styling possibilities for the "androidNative" picker variant.

### Divider color

<img src="docs/divider-color.png" alt="react native date picker divider separator color" width="200px" />

To change the divider color, open `styles.xml` and place this code right above the `</resources>`.

```xml
<style name="DatePickerTheme" parent="DatePickerBaseTheme">
<item name="android:colorControlNormal">#dd00ff</item>
</style>
```

### Button colors

<img src="docs/button-colors.png" alt="date picker button colors on android" width="200px" />

To change the confirm and cancel button colors. Open `styles.xml` and place this code within your theme.

```xml
<item name="colorAccent">#dd00ff</item>
```

### Font size

To change the font size on Android `nativeAndroid` variant. Open `styles.xml` and place this code right above the `</resources>`. The font size is not possible to change in iOS out of the box, but there are some [iOS workarounds](https://github.com/henninghall/react-native-date-picker/discussions/171).
To change the font size on Android. Open `styles.xml` and place this code right above the `</resources>`. The font size is not possible to change in iOS out of the box, but there are some [iOS workarounds](https://github.com/henninghall/react-native-date-picker/discussions/171).

```xml
<style name="DatePickerTheme" parent="DatePickerBaseTheme">
Expand Down Expand Up @@ -238,36 +210,6 @@ const [state, setState] = useState("idle")
<ConfirmButton disabled={state === "spinning"} />
```

## Two different Android variants

On Android there are two design variants to choose from:

<table>
<tr><td align="center"><b>iOS clone</b></td><td align="center"><b>Native Android</b></td>
</tr><tr><td align="center">
<img src="docs/react-native-date-picker-android.gif" alt="date time picker" height="150px" />
</td><td align="center">
<img src="docs/react-native-date-picker-android-native.gif" alt="date time picker" height="150px" />
</td></tr>

<tr><td>The so called "iOS clone" looks and works similar to the ios version. It shows normally 5 lines of dates. It is enabled by default.</td><td>
The "Android Native" version looks more like a standard native implementation on Android.
</td></tr>
<tr><td>

```js
androidVariant = 'iosClone'
```

</td><td>

```js
androidVariant = 'nativeAndroid'
```

</td></tr>
</table>

## Three different modes

Here are some more info about the three different picker modes that are available.
Expand Down
1 change: 0 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ if (isNewArchitectureEnabled()) {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.facebook.react:react-native:+'
implementation 'com.github.henninghall:numberpickerview:v1.1.5'
implementation 'org.apache.commons:commons-lang3:3.8'
implementation group: 'net.time4j', name: 'time4j-android', version: '4.8-2021a'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public static void receiveCommand(final PickerView view, int commandId, final Re
}
}



public static void updateProp(String methodName, PickerView view, int index, Dynamic value, Class<? extends com.henninghall.date_picker.DatePickerManager> aClass){
String[] propNames = getMethodAnnotation(methodName, aClass).names();
String propName = propNames[index];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.henninghall.date_picker;

import android.text.format.DateFormat;
import android.util.Log;
import android.util.TimeUtils;

import com.henninghall.date_picker.models.Mode;
import com.henninghall.date_picker.models.Variant;
import com.henninghall.date_picker.models.WheelType;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
Expand Down Expand Up @@ -99,23 +95,8 @@ private ArrayList<WheelType> getOrderedWheels() {
return orderedWheels;
}

public int getShownCount() {
int DP_PER_SHOW_SHOW_COUNT = 35;
int showCount = state.getHeight() / DP_PER_SHOW_SHOW_COUNT;
int oddShowCount = showCount % 2 == 0 ? showCount + 1 : showCount;
return oddShowCount;
}

public boolean hasNativeStyle() {
return state.getVariant() == Variant.nativeAndroid;
}

public int getRootLayout() {
switch (state.getVariant()){
case nativeAndroid: return R.layout.native_picker;
case iosClone: return R.layout.ios_clone;
default: return R.layout.ios_clone;
}
return R.layout.native_picker;
}

public boolean usesAmPm(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.henninghall.date_picker;

import com.henninghall.date_picker.models.Variant;

/**
* This workaround prevents a bug existing in the NativeAndroid variant.
* The bug displays duplicated "12" hours string when the current time is set to "1".
Expand All @@ -21,7 +19,6 @@ public HourDisplayBugWorkaround(State state) {
}

private boolean shouldApply(String displayValue) {
if(state.getVariant() != Variant.nativeAndroid) return false;
if(displayValue.length() != 1) return false;
return true;
}
Expand Down
Loading
Loading