zhigang1992 / react-native-jsonschema-form

react native implementation of https://github.com/rjsf-team/react-jsonschema-form
29 stars 20 forks source link

Support for more recent versions @rjsf/core (^4.0.0) #34

Open chriscoomber opened 2 years ago

chriscoomber commented 2 years ago

Issue

Currently, this package depends on "@rjsf/core": "^2.0.0". However this is a very old version, and has scary warnings about peer dependencies like:

warning @rjsf/core > core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.

Discussion

It would be good to support the latest version of @rjsf/core.

I feel like this might be a relatively small fix, because from testing against @rjsf/core ^4.0.0, I only get crashes on react-native when my schema uses arrays. Specifically I see:

ReferenceError: Can't find variable: crypto

This error is located at:
    in ArrayField (created by SchemaField)
    ...

So probably @rjsf/core has added a new ArrayField that we need to provide a react-native alternative for (I'm not an expert on how this package works).

Aside: I realise that this is a very niche library that's not actively maintained, so if anyone reading this can point me to an alternative, that would be very useful. I took a look at https://github.com/CareLuLu/react-native-web-jsonschema-form but had trouble getting it working.

chriscoomber commented 2 years ago

Looks like you can get around the crypto error with:

import 'react-native-get-random-values'; // Polyfill for crypto library on native.

(and obviously add that package to your package.json) above your import for this package. Otherwise, it seems to be fine with targeting @rjsf/core (^4.0.0)