Skip to content

fix: use android resource ids instead of names #541

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

Merged
merged 2 commits into from
Dec 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/github",
[
"@semantic-release/github",
{
"successComment": ":tada: This issue has been resolved in version ${nextRelease.version} :tada:\n\nIf this package helps you, consider [sponsoring us](https://github.com/sponsors/react-native-datetimepicker)! :rocket:",
"addReleases": "bottom"
}
],
[
"@semantic-release/git",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,12 @@ DatePickerDialog getDialog(
switch (display) {
case CALENDAR:
case SPINNER:
String resourceName = display == RNDatePickerDisplay.CALENDAR
? "CalendarDatePickerDialog"
: "SpinnerDatePickerDialog";
int theme = display == RNDatePickerDisplay.CALENDAR
? R.style.CalendarDatePickerDialog
: R.style.SpinnerDatePickerDialog;
return new RNDismissableDatePickerDialog(
activityContext,
activityContext.getResources().getIdentifier(
resourceName,
"style",
activityContext.getPackageName()),
theme,
onDateSetListener,
year,
month,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,12 @@ static TimePickerDialog getDialog(
}

if (display == RNTimePickerDisplay.CLOCK || display == RNTimePickerDisplay.SPINNER) {
String resourceName = display == RNTimePickerDisplay.CLOCK
? "ClockTimePickerDialog"
: "SpinnerTimePickerDialog";
int theme = display == RNTimePickerDisplay.CLOCK
? R.style.ClockTimePickerDialog
: R.style.SpinnerTimePickerDialog;
return new RNDismissableTimePickerDialog(
activityContext,
activityContext.getResources().getIdentifier(
resourceName,
"style",
activityContext.getPackageName()
),
theme,
onTimeSetListener,
hour,
minute,
Expand Down
26 changes: 26 additions & 0 deletions android/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="SpinnerDatePickerDialog" parent="Theme.AppCompat.Light.Dialog" tools:targetApi="lollipop">
<item name="android:datePickerStyle">@style/SpinnerDatePickerStyle</item>
</style>

<style name="SpinnerDatePickerStyle" parent="android:Widget.Material.Light.DatePicker" tools:targetApi="lollipop">
<item name="android:datePickerMode">spinner</item>
</style>

<style name="CalendarDatePickerDialog" parent="Theme.AppCompat.Light.Dialog" tools:targetApi="lollipop">
<item name="android:datePickerStyle">@style/CalendarDatePickerStyle</item>
</style>

<style name="CalendarDatePickerStyle" parent="android:Widget.Material.Light.DatePicker" tools:targetApi="lollipop">
<item name="android:datePickerMode">calendar</item>
</style>


<style name="ClockTimePickerDialog" parent="Theme.AppCompat.Light.Dialog" tools:targetApi="lollipop">
<item name="android:timePickerStyle">@style/ClockTimePickerStyle</item>
</style>

<style name="ClockTimePickerStyle" parent="android:Widget.Material.Light.TimePicker" tools:targetApi="lollipop">
<item name="android:timePickerMode">clock</item>
</style>

<style name="SpinnerTimePickerDialog" parent="Theme.AppCompat.Light.Dialog" tools:targetApi="lollipop">
<item name="android:timePickerStyle">@style/SpinnerTimePickerStyle</item>
</style>

<style name="SpinnerTimePickerStyle" parent="android:Widget.Material.Light.TimePicker" tools:targetApi="lollipop">
<item name="android:timePickerMode">spinner</item>
</style>
Expand Down
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def jscFlavor = 'org.webkit:android-jsc:+'
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);
def enableHermes = project.ext.react.get("enableHermes", false)

/**
* Architectures to build native code for in debug.
Expand Down Expand Up @@ -221,7 +221,7 @@ dependencies {
androidTestImplementation('com.wix:detox:+')

if (enableHermes) {
def hermesPath = "../../../node_modules/hermes-engine/android/";
def hermesPath = "../../../node_modules/hermes-engine/android/"
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
Expand Down
22 changes: 13 additions & 9 deletions example/e2e/detoxTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
userDismissesCompactDatePicker,
} = require('./utils/actions');
const {isIOS, wait, Platform} = require('./utils/utils');
const {device} = require('detox');

describe('Example', () => {
const getPickerDisplay = () => {
Expand Down Expand Up @@ -82,18 +83,21 @@ describe('Example', () => {

if (isIOS()) {
const testElement = getDateTimePickerControlIOS();
await testElement.setDatePickerDate('2021-12-12', 'yyyy-MM-dd');
await testElement.setDatePickerDate('2021-11-02', 'yyyy-MM-dd');
} else {
const calendarHorizontalScrollView = element(
by
.type('android.widget.ScrollView')
.withAncestor(by.type('android.widget.DatePicker')),
);
await calendarHorizontalScrollView.swipe('left', 'fast', 1);
await calendarHorizontalScrollView.tap({x: 50, y: 200}); // select some date
const uiDevice = device.getUiDevice();
const focusSecondOfNovemberInCalendar = async () => {
await uiDevice.pressDPadDown();
await uiDevice.pressDPadDown();
await uiDevice.pressDPadDown();
};
await focusSecondOfNovemberInCalendar();

await uiDevice.pressEnter();

await userTapsOkButtonAndroid();
}
await expect(getDateText()).toHaveText('12/12/2021');
await expect(getDateText()).toHaveText('11/02/2021');
});

it('should show time picker after tapping timePicker button', async () => {
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@
"@react-native-segmented-control/segmented-control": "^2.4.0",
"@semantic-release/git": "^10.0.1",
"@testing-library/react-native": "^8.0.0",
"babel-jest": "^27.3.1",
"detox": "19.0.0",
"babel-jest": "^27.4.4",
"detox": "19.3.0",
"eslint": "^7",
"eslint-plugin-prettier": "^4.0.0",
"flow-bin": "^0.158.0",
"flow-typed": "^3.4.0",
"jest": "^27.3.1",
"jest-circus": "^27.3.1",
"jest": "^27.4.4",
"jest-circus": "^27.4.4",
"metro-react-native-babel-preset": "^0.66.2",
"moment": "^2.24.0",
"prettier": "^2.4.1",
"prettier": "^2.5.1",
"react": "17.0.2",
"react-native": "^0.66.3",
"react-native-localize": "^2.1.5",
"react-native": "^0.66.4",
"react-native-localize": "^2.1.6",
"react-native-windows": "^0.66.3",
"react-test-renderer": "17.0.2",
"semantic-release": "^18.0.0"
"semantic-release": "^18.0.1"
},
"dependencies": {
"invariant": "^2.2.4"
Expand Down
Loading