instamobile / react-native-firebase

React Native Firebase Starter Project with Auth, Firestore, Storage and Push Notifications
https://instamobile.io
MIT License
413 stars 139 forks source link

White screen on initial yarn ios #1

Open ironspur5 opened 4 years ago

ironspur5 commented 4 years ago

Step 4 Implement the UI in the accompanying guide leads to a white screen blank expo app on iOS simulator when login and registration should be showing up.

harrytruong commented 4 years ago

I assume you're referring to Step 4 from this guide: https://www.freecodecamp.org/news/react-native-firebase-tutorial/

The white screen blank issue comes from the code for App.js as described in Step 3:

  if (loading) {
    return (
      <></>
    )
  }

I think the author (cc @mrcflorian) made a mistake here, and did not mean to include this return (<></>) render logic as part of Step 3, since there's no corresponding logic to update loading to become false (This gets implemented later, in Step 7 of the guide.)

QUICK FIX:

If you've completed Step 4, and don't see the UI with the login/registration screens, then you should update App.js and just comment out the loading state render logic:

//  if (loading) {
//    return (
//      <></>
//    )
//  }

RECOMMENDED FIX:

@mrcflorian Would you mind fixing Step 3 of the tutorial?

mrcflorian commented 4 years ago

Thanks for taking a look guys. @harrytruong is right. I've just updated the tutorial.

harrytruong commented 4 years ago

Damn @mrcflorian, that was a crazy fast response, haha. Thank you for the very quick update! (I'm pointing my intern to your tutorial to help them learn React Native, and it's been very helpful so far.)

If you have time, I think you might want to review your tutorial one more time:

mrcflorian commented 4 years ago

I've updated the loading thing again, to reflect the right order. Home has been defined at step 3, so it should be available already at step 7/8.

harrytruong commented 4 years ago

Home has been defined at step 3, so it should be available already at step 7/8.

Yeah, but it's conditionally rendered based on the user value (which is defaulted to null, and doesn't get updated by Step 5)

        { user ? (
          <Stack.Screen name="Home">
            {props => <HomeScreen {...props} extraData={user} />}
          </Stack.Screen>
        ) : (
          <>
            <Stack.Screen name="Login" component={LoginScreen} />
            <Stack.Screen name="Registration" component={RegistrationScreen} />
          </>
        )}

@mrcflorian I might be wrong, but it seems like without <Stack.Screen name="Home" /> being rendered, the calls to navigation.navigate('Home', ...) in Step 5 & 6 would fail?

(It all works properly by the end of Step 7, when setUser() is added. The problem is just that it's in a broken state by the end of the Step 5 of your tutorial.)

ironspur5 commented 4 years ago

Thank you both very much for looking at this issue! I'n new to React Native, so I'll continue to follow this thread to see a complete resolution.

tpssim commented 4 years ago

Home has been defined at step 3, so it should be available already at step 7/8.

Yeah, but it's conditionally rendered based on the user value (which is defaulted to null, and doesn't get updated by Step 5)

        { user ? (
          <Stack.Screen name="Home">
            {props => <HomeScreen {...props} extraData={user} />}
          </Stack.Screen>
        ) : (
          <>
            <Stack.Screen name="Login" component={LoginScreen} />
            <Stack.Screen name="Registration" component={RegistrationScreen} />
          </>
        )}

@mrcflorian I might be wrong, but it seems like without <Stack.Screen name="Home" /> being rendered, the calls to navigation.navigate('Home', ...) in Step 5 & 6 would fail?

(It all works properly by the end of Step 7, when setUser() is added. The problem is just that it's in a broken state by the end of the Step 5 of your tutorial.)

The registration remains broken even after Step 7. Just remove the user from Firebase console and try to sign up again. You will get the same navigation error and after a reload you get to home screen because of the persistent login.

Because of the conditional render 'Home' screen won't exist simultaneously with 'Login' and 'Registration' and thus the navigator cant find 'Home' when called from 'Login' or 'Registration.'

Edit: Here is a way to move from login to home without using NAVIGATE: https://reactnavigation.org/docs/auth-flow