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

Add React Native adaptor #46

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add React Native adaptor #46

wants to merge 4 commits into from

Conversation

kossnocorp
Copy link
Owner

Add experimental React Native adaptor.

src/adaptor/native.ts Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@kossnocorp
Copy link
Owner Author

@pie6k thank you so much for the review! I managed to get rid of all untyped imports except DocumentReference that isn't exported. I also released typesaurus@6.1.0-alpha.2.


export default async function adaptor() {
const firestore = nativeFirestore()
// At the moment, the React Native Firebase adaptor doesn't support getAll.
if (!('getAll' in firestore)) Object.assign(firestore, { getAll })
return {
firestore,
consts: { DocumentReference, Timestamp, FieldValue }
consts: {
DocumentReference,
Copy link

@pie6k pie6k Apr 22, 2020

Choose a reason for hiding this comment

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

Seems like DocumentReference is indeed not exported from public API of the package...

https://github.com/invertase/react-native-firebase/blob/master/packages/firestore/lib/FirestoreStatics.js

@kossnocorp
Copy link
Owner Author

@pie6k did you have a chance if It worked? 🤞

@hotchpotch
Copy link
Contributor

Hi!

I'm using typesaurus with firebase(web) package on react-native. It works well.
I don't use react-native-firebase.

However if this pull request will merge, I can't use firebase(web) with react-native.

Can I switch adopter by manually?

for example interface.

import { setAdopter } from "typesaurus"
import * as firebase from 'firebase/app' // web adaptor

setAdopter(firebase.firestore())

@kossnocorp
Copy link
Owner Author

@hotchpotch that's terrible news but great timing! I guess I have to figure out how to make them all work together.

It's not possible to change adaptor on the web, but even if I add the ability, your case will break with an error "missing react-native-firebase". So I don't think that's an option.

@pie6k I'm wondering tho, what's the advantages of react-native-firebase over the web firebase package?

@pie6k
Copy link

pie6k commented May 22, 2020

Hey, sorry for not testing your PR deeper. I switched to different approach and didn't have time to play with it.

There are quite a lot of advantages of using it over web based lib in React Native
eg.

  • firestore uses some sort of native database for offline support in react native firebase
  • react native firestore uses native bootstrap code, so you can know if user is logged in in sync way. With 'plain web' solution there is no way to read any persisted data in a sync way. it's useful if you want to make some decisions quickly depending on auth state when starting the app
  • it integrates with native authorization methods eg. using app models for showing facebook auth window
  • it supports managing native notifications permissions
  • support of attaching native views to analytics of firebase
    etc.

@hotchpotch
Copy link
Contributor

hotchpotch commented Jun 12, 2020

I think @firebase/firestore or @react-native-firebase each has pros and const.

  • @firebase/firestore is pure JavaScript library. No need native module compile. So @firebase/firestore works well with Expo
  • @firebase/firestore is Google official library.
  • @react-native-firebase is not Google official library. Don't work with Expo.
    • But It has some advantages than @firebase/firestore.

I'm using @firebase/firestore with react-native (with Expo).

So I would be happy if there was a way to select @firebase/firestore or @react-native-firebase.
However, I don't know how it works...

@hotchpotch
Copy link
Contributor

hotchpotch commented Jun 12, 2020

I looked into about dynamic import with react-native.

Currently (react-native <=0.62) , it is not work yet.

However, next react-native version 0.63, Dynamic import will probably work.

Example implmention

@darlanjunior
Copy link

Hi!
I'd like to know if you plan on merging this PR still. Using the 6.1.0-alpha.2 works but some typings are incorrect (which I imagine were fixed on 7.0.0 an onwards)

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

Successfully merging this pull request may close these issues.

4 participants