Skip to content

Commit

Permalink
[android][ios] Upgrade @react-native-community/datetimepicker to 7.1.0 (
Browse files Browse the repository at this point in the history
expo#22894)

# Why

Upgrades `@react-native-community/datetimepicker`  to `7.1.0`
 

# How

```sh
et uvm -m @react-native-community/datetimepicker -c "v7.1.0"
yarn 
et pods -f
```


# Test Plan

- [x] test using `bare-expo` Android + NCL DateTimePicker Example 
- [x] test using `bare-expo` iOS + NCL DateTimePickerExample
- [x] test unversioned expo go ios + NCL DateTimePicker Example
- [x] test unversioned expo go android + NCL DateTimePicker Example

# Checklist
 

- [x] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [x] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [x] This diff will work correctly for `expo prebuild` & EAS Build (eg:
updated a module plugin).
  • Loading branch information
gabrieldonadel authored Jun 19, 2023
1 parent 0ac9312 commit 5b07ee5
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static int getDefaultDialogButtonTextColor(@NonNull Context activity) {
}

@NonNull
public static DialogInterface.OnShowListener setButtonTextColor(@NonNull Context activityContext, final AlertDialog dialog, final Bundle args, final boolean needsColorOverride) {
public static DialogInterface.OnShowListener setButtonTextColor(@NonNull final Context activityContext, final AlertDialog dialog, final Bundle args, final boolean needsColorOverride) {
return new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
* {@link NativeModule} that allows JS to show a native date picker dialog and get called back when
* the user selects a date.
*/
@ReactModule(name = RNDatePickerDialogModule.FRAGMENT_TAG)
public class RNDatePickerDialogModule extends ReactContextBaseJavaModule {
@ReactModule(name = DatePickerModule.NAME)
public class DatePickerModule extends NativeModuleDatePickerSpec {

@VisibleForTesting
public static final String FRAGMENT_TAG = "RNDatePickerAndroid";
public static final String NAME = "RNDatePicker";

public RNDatePickerDialogModule(ReactApplicationContext reactContext) {
public DatePickerModule(ReactApplicationContext reactContext) {
super(reactContext);
}

@Override
public @NonNull String getName() {
return RNDatePickerDialogModule.FRAGMENT_TAG;
return NAME;
}

private class DatePickerDialogListener implements OnDateSetListener, OnDismissListener, OnClickListener {
Expand Down Expand Up @@ -115,7 +115,7 @@ public void onClick(DialogInterface dialog, int which) {
@ReactMethod
public void dismiss(Promise promise) {
FragmentActivity activity = (FragmentActivity) getCurrentActivity();
dismissDialog(activity, FRAGMENT_TAG, promise);
dismissDialog(activity, NAME, promise);
}
/**
* Show a date picker dialog.
Expand Down Expand Up @@ -147,8 +147,8 @@ public void open(final ReadableMap options, final Promise promise) {
FragmentActivity activity = (FragmentActivity) getCurrentActivity();
if (activity == null) {
promise.reject(
RNConstants.ERROR_NO_ACTIVITY,
"Tried to open a DatePicker dialog while not attached to an Activity");
RNConstants.ERROR_NO_ACTIVITY,
"Tried to open a DatePicker dialog while not attached to an Activity");
return;
}

Expand All @@ -158,7 +158,7 @@ public void open(final ReadableMap options, final Promise promise) {
@Override
public void run() {
RNDatePickerDialogFragment oldFragment =
(RNDatePickerDialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
(RNDatePickerDialogFragment) fragmentManager.findFragmentByTag(NAME);

if (oldFragment != null) {
oldFragment.update(createFragmentArguments(options));
Expand All @@ -173,7 +173,7 @@ public void run() {
fragment.setOnDismissListener(listener);
fragment.setOnDateSetListener(listener);
fragment.setOnNeutralButtonActionListener(listener);
fragment.show(fragmentManager, FRAGMENT_TAG);
fragment.show(fragmentManager, NAME);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Then it was commited. It is here to support the old architecture.
* If you use the new architecture, this file won't be included and instead will be generated by the codegen.
*
* @generated by codegen project: GenerateModuleJavaSpec.js
*
* @nolint
*/

package versioned.host.exp.exponent.modules.api.components.datetimepicker;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactModuleWithSpec;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;

public abstract class NativeModuleDatePickerSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public NativeModuleDatePickerSpec(ReactApplicationContext reactContext) {
super(reactContext);
}

@ReactMethod
@DoNotStrip
public abstract void dismiss(Promise promise);

@ReactMethod
@DoNotStrip
public abstract void open(ReadableMap params, Promise promise);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Then it was commited. It is here to support the old architecture.
* If you use the new architecture, this file won't be included and instead will be generated by the codegen.
*
* @generated by codegen project: GenerateModuleJavaSpec.js
*
* @nolint
*/

package versioned.host.exp.exponent.modules.api.components.datetimepicker;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactModuleWithSpec;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;

public abstract class NativeModuleTimePickerSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public NativeModuleTimePickerSpec(ReactApplicationContext reactContext) {
super(reactContext);
}

@ReactMethod
@DoNotStrip
public abstract void dismiss(Promise promise);

@ReactMethod
@DoNotStrip
public abstract void open(ReadableMap params, Promise promise);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

package versioned.host.exp.exponent.modules.api.components.datetimepicker;

import host.exp.expoview.R;

import static versioned.host.exp.exponent.modules.api.components.datetimepicker.Common.getDisplayDate;
import static versioned.host.exp.exponent.modules.api.components.datetimepicker.Common.setButtonTextColor;
import static versioned.host.exp.exponent.modules.api.components.datetimepicker.Common.setButtonTitles;
Expand All @@ -27,12 +25,15 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import android.widget.DatePicker;

import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;

import host.exp.expoview.R;

@SuppressLint("ValidFragment")
public class RNDatePickerDialogFragment extends DialogFragment {
private DatePickerDialog instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,73 @@
package versioned.host.exp.exponent.modules.api.components.datetimepicker;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.facebook.react.ReactPackage;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.TurboReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

public class RNDateTimePickerPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(
new RNDatePickerDialogModule(reactContext),
new RNTimePickerDialogModule(reactContext)
);
}
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
import host.exp.expoview.BuildConfig;

public class RNDateTimePickerPackage extends TurboReactPackage {
@Nullable
@Override
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
if (name.equals(DatePickerModule.NAME)) {
return new DatePickerModule(reactContext);
} else if (name.equals(TimePickerModule.NAME)) {
return new TimePickerModule(reactContext);
} else {
return null;
}
}

@Override
public ReactModuleInfoProvider getReactModuleInfoProvider() {
return () -> {
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
moduleInfos.put(
DatePickerModule.NAME,
new ReactModuleInfo(
DatePickerModule.NAME,
DatePickerModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
));
moduleInfos.put(
TimePickerModule.NAME,
new ReactModuleInfo(
TimePickerModule.NAME,
TimePickerModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
));
return moduleInfos;
};
}

@NonNull
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new DatePickerModule(reactContext));
modules.add(new TimePickerModule(reactContext));

return modules;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package versioned.host.exp.exponent.modules.api.components.datetimepicker;

import host.exp.expoview.R;

import static versioned.host.exp.exponent.modules.api.components.datetimepicker.Common.getDisplayTime;
import static versioned.host.exp.exponent.modules.api.components.datetimepicker.Common.setButtonTextColor;
import static versioned.host.exp.exponent.modules.api.components.datetimepicker.Common.setButtonTitles;
Expand All @@ -28,6 +26,8 @@
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import host.exp.expoview.R;

@SuppressWarnings("ValidFragment")
public class RNTimePickerDialogFragment extends DialogFragment {
private TimePickerDialog instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@
* {@link NativeModule} that allows JS to show a native time picker dialog and get called back when
* the user selects a time.
*/
@ReactModule(name = RNTimePickerDialogModule.FRAGMENT_TAG)
public class RNTimePickerDialogModule extends ReactContextBaseJavaModule {
@ReactModule(name = TimePickerModule.NAME)
public class TimePickerModule extends NativeModuleTimePickerSpec {

@VisibleForTesting
public static final String FRAGMENT_TAG = "RNTimePickerAndroid";
public static final String NAME = "RNTimePicker";

public RNTimePickerDialogModule(ReactApplicationContext reactContext) {
public TimePickerModule(ReactApplicationContext reactContext) {
super(reactContext);
}

@NonNull
@Override
public String getName() {
return FRAGMENT_TAG;
return NAME;
}

private class TimePickerDialogListener implements OnTimeSetListener, OnDismissListener, OnClickListener {
Expand Down Expand Up @@ -89,16 +89,16 @@ public void onClick(DialogInterface dialog, int which) {
@ReactMethod
public void dismiss(Promise promise) {
FragmentActivity activity = (FragmentActivity) getCurrentActivity();
dismissDialog(activity, FRAGMENT_TAG, promise);
dismissDialog(activity, NAME, promise);
}

@ReactMethod
public void open(final ReadableMap options, final Promise promise) {
FragmentActivity activity = (FragmentActivity) getCurrentActivity();
if (activity == null) {
promise.reject(
RNConstants.ERROR_NO_ACTIVITY,
"Tried to open a TimePicker dialog while not attached to an Activity");
RNConstants.ERROR_NO_ACTIVITY,
"Tried to open a TimePicker dialog while not attached to an Activity");
return;
}
// We want to support both android.app.Activity and the pre-Honeycomb FragmentActivity
Expand All @@ -109,7 +109,7 @@ public void open(final ReadableMap options, final Promise promise) {
@Override
public void run() {
RNTimePickerDialogFragment oldFragment =
(RNTimePickerDialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
(RNTimePickerDialogFragment) fragmentManager.findFragmentByTag(NAME);

if (oldFragment != null) {
oldFragment.update(createFragmentArguments(options));
Expand All @@ -124,7 +124,7 @@ public void run() {
fragment.setOnDismissListener(listener);
fragment.setOnTimeSetListener(listener);
fragment.setOnNeutralButtonActionListener(listener);
fragment.show(fragmentManager, FRAGMENT_TAG);
fragment.show(fragmentManager, NAME);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions apps/bare-expo/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ PODS:
- React-Core
- RNCPicker (2.4.8):
- React-Core
- RNDateTimePicker (6.7.3):
- RNDateTimePicker (7.1.0):
- React-Core
- RNFlashList (1.4.3):
- React-Core
Expand Down Expand Up @@ -1497,7 +1497,7 @@ SPEC CHECKSUMS:
RNCAsyncStorage: ddc4ee162bfd41b0d2c68bf2d95acd81dd7f1f93
RNCMaskedView: 949696f25ec596bfc697fc88e6f95cf0c79669b6
RNCPicker: 0bf8ef8f7800524f32d2bb2a8bcadd53eda0ecd1
RNDateTimePicker: 00247f26c34683c80be94207f488f6f13448586e
RNDateTimePicker: 7ecd54a97fc3749f38c3c89a171f6cbd52f3c142
RNFlashList: ade81b4e928ebd585dd492014d40fb8d0e848aab
RNGestureHandler: dec4645026e7401a0899f2846d864403478ff6a5
RNReanimated: b4f101902606e60b4b045e813e47204c2d7b38a7
Expand Down
2 changes: 1 addition & 1 deletion apps/bare-expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"dependencies": {
"@babel/runtime": "^7.20.0",
"@react-native-async-storage/async-storage": "1.18.2",
"@react-native-community/datetimepicker": "6.7.3",
"@react-native-community/datetimepicker": "7.1.0",
"@react-native-community/netinfo": "9.3.10",
"@react-native-community/slider": "4.4.2",
"@react-native-masked-view/masked-view": "0.2.9",
Expand Down
2 changes: 1 addition & 1 deletion apps/native-component-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@expo/react-native-action-sheet": "^3.8.0",
"@react-native-async-storage/async-storage": "1.18.2",
"@react-native-community/datetimepicker": "6.7.3",
"@react-native-community/datetimepicker": "7.1.0",
"@react-native-community/netinfo": "9.3.10",
"@react-native-community/slider": "4.4.2",
"@react-native-masked-view/masked-view": "0.2.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/bundledNativeModules.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"@expo/vector-icons": "^13.0.0",
"@react-native-async-storage/async-storage": "1.18.2",
"@react-native-community/datetimepicker": "6.7.3",
"@react-native-community/datetimepicker": "7.1.0",
"@react-native-masked-view/masked-view": "0.2.9",
"@react-native-community/netinfo": "9.3.10",
"@react-native-community/slider": "4.4.2",
Expand Down
Loading

0 comments on commit 5b07ee5

Please sign in to comment.