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: implement imperative api for android picker #574

Merged
merged 14 commits into from
Mar 11, 2022
Merged

Conversation

vonovak
Copy link
Member

@vonovak vonovak commented Mar 7, 2022

Summary

On Android, this gives a choice between using the component API (regular React component) or an imperative api (think something like ReactNative.alert()).

The component API has the benefit of writing the same code on all platforms, but on Android, the date/time picker opens in a dialog, similar to ReactNative.alert() from core react native. The imperative api models this behavior better than the declarative component api. While the component approach is perfectly functional, based on the issue tracker history, it appears to be more prone to introducing bugs.

Test Plan

The component api internally uses the newly added imperative one, and so the e2e tests which are written using the component api also cover the new imperative one

Compatibility

OS Implemented
iOS
Android

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I updated the typed files (TS and Flow)
  • I added a sample use of the API in the example project (example/App.js)
  • I have added automated tests, either in JS or e2e tests, as applicable

@vonovak vonovak marked this pull request as ready for review March 11, 2022 03:20
@vonovak vonovak merged commit 5861042 into master Mar 11, 2022
@vonovak vonovak deleted the feat/imperative-api branch March 11, 2022 03:26
vonovak pushed a commit that referenced this pull request Mar 11, 2022
# [6.0.0](v5.1.0...v6.0.0) (2022-03-11)

### Features

* expose imperative api for android picker ([#574](#574)) ([5861042](5861042))

### BREAKING CHANGES

* actually, should not be breaking but there were changes in typings
@vonovak
Copy link
Member Author

vonovak commented Mar 11, 2022

🎉 This issue has been resolved in version 6.0.0 🎉

If this package helps you, consider sponsoring us! 🚀

@@ -22,6 +22,7 @@
"start:windows": "react-native start --use-react-native-windows",
"test": "jest ./test",
"posttest": "npm run lint",
"postinstall": "patch-package",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vonovak is this a leftover? because patch-package is in devDependencies, so installing 6.0 produces an error

presentPicker();
}

function dismiss(mode: AndroidNativeProps['mode']) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax seem to be invalid with older versions of RN/flow (tested on RN 63.3/flow 0.122.0):

error: SyntaxError: .../node_modules/@react-native-community/datetimepicker/src/DateTimePickerAndroid.js: Unexpected token, expected "]" (97:42)

   95 | }
   96 |
>  97 | function dismiss(mode: AndroidNativeProps['mode']) {
      |                                           ^
   98 |   // $FlowFixMe - `AbstractComponent` [1] is not an instance type.
   99 |   pickers[mode].dismiss();
  100 | }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello, yes, you'll need Flow 155: https://flow.org/en/docs/types/indexed-access/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not using flow in project RN 0.63.4 and having this issue. Not sure how to fix. Do you have a workaround?
Tried to use older versions which is 5.1.0 and 3.5.2 but for those i am getting "Unhandled promise rejection [TypeError: Cannot read property 'open' of null" any idea or guidence to help on this?

vonovak pushed a commit that referenced this pull request Apr 29, 2022
* Fix Break in Windows

* Fix Format

* Fix Format

* Add Type Info
vonovak pushed a commit that referenced this pull request Apr 29, 2022
## [6.1.3](v6.1.2...v6.1.3) (2022-04-29)

### Bug Fixes

* Break in Windows JS following [#574](#574) ([#605](#605)) ([24f3452](24f3452))
@TechWithMuskan
Copy link

@flochtililoch Have you found any solution of this error, experiencing same
error: SyntaxError: /Users/Documents/MyFirstApp/node_modules/@react-native-community/datetimepicker/src/DateTimePickerAndroid.android.js: Unexpected token, expected "]"

@sedatbasar
Copy link

@flochtililoch Have you found any solution of this error, experiencing same error: SyntaxError: /Users/Documents/MyFirstApp/node_modules/@react-native-community/datetimepicker/src/DateTimePickerAndroid.android.js: Unexpected token, expected "]"

Used older versions of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants