React Native app is stuck on splash screen after adding React Navigation using Stack.Screen (iOS/Android) - react-native

Like the question says, I was following a tutorial and it was working fine so I wanted to implement it into my own side project app.
After adding it exactly the same as the doc says the component in the <Stack.Screen/> won't load.
I have tried multiple things but nothing seems to work. No errors either so I'm stuck on how to debug.
As I don't know which part of my code is causing the problem I will post my github repo link here.
https://github.com/totablue/ToyBoxOfWords

Answering my own question.
The thing that was causing my app to get stuck on the splashscreen was the SplashScreen.preventAutoHideAsync()
that was called while the app was loading the font.
const onLayoutRootView = useCallback(async () => {
if (fontsLoaded) {
await SplashScreen.hideAsync();
}
}, [fontsLoaded]);
this part of the code was not running so the splash screen never went away.
Used this video to load custom fonts in a different way and it fixed everything.
https://youtu.be/viIkcDYSBrI

I have tried to run your code, and it worked well. The problem is that you have not added some dependencies!
This is the package.json file that I use with your code.
{
"dependencies": {
"expo-font": "~10.2.0",
"expo-constants": "~13.2.4",
"expo-status-bar": "~1.4.0",
"#expo/vector-icons": "^13.0.0",
"expo-splash-screen": "~0.16.2",
"react-native-paper": "4.9.2",
"react-native-screens": "~3.15.0",
"#react-navigation/native": "*",
"#react-navigation/native-stack": "*",
"react-native-safe-area-context": "4.3.1"
}
}

Related

Using custom fonts in Expo / Next.js: Module parse failed

EDIT: Instead of using Expo Fonts, I tried importing them from Google Fonts into the <Head/> under _document.js like so:
<Head>
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght#400;500;700&family=Poppins:wght#300;400;500;600;700&display=swap" rel="stylesheet" />
</Head>
And it works wonderfully!
Original Question:
I have tried following Expo and my current next.config.js looks like this:
const { withExpo } = require("#expo/next-adapter");
const withFonts = require("next-fonts");
/** #type {import('next').NextConfig} */
const nextConfig = withExpo(
{
reactStrictMode: true,
swcMinify: true,
transpilePackages: [
"react-native",
"expo",
"expo-linear-gradient",
"expo-font",
"react-native-svg",
"lucide-react-native",
"prop-types",
// Add more React Native / Expo packages here...
],
experimental: {
forceSwcTransforms: true,
},
},
withFonts({
projectRoot: __dirname,
})
);
module.exports = nextConfig;
However, I keep getting the following error in the debug window:
./public/fonts/SpaceMono-Regular.ttf
Module parse failed: Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
Current dependencies:
"dependencies": {
"expo": "^47.0.0",
"expo-font": "~11.0.1",
"expo-linear-gradient": "~12.0.1",
"lucide-react-native": "^0.115.0",
"next": "~13.1.1",
"next-fonts": "^1.5.1",
"prop-types": "^15.8.1",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-native": "0.70.5",
"react-native-svg": "13.4.0",
"react-native-web": "~0.18.7"
},
I am enjoying using Next.js so far and this was my first bump on the road.
Thank you!
I've already searched and found some answers I could not replicate. The obvious answer would be my project do not know how to load .ttf and it should be fixed with Next-fonts. But I do not know how to set it up properly and tried various combinations from Stack and Expo with a few success, but the instant I changed font to e.g. Poppins or DM Sans, then the error instantly returned, even through the space-mono font worked a few times. I have no idea why it suddenly worked and suddenly didn't.

Invalid UIAccessibilityTraits 'tablist' using #react-navigation/material-bottom-tabs

I get the following error after installing #react-navigation/material-bottom-tabs react-native-paper react-native-vector-icons and creating a stack following the example at https://reactnavigation.org/docs/material-bottom-tab-navigator/#example:
Error setting property 'accessibilityRole' of RCTView with tag #227: Invalid UIAccessibilityTraits 'tablist'. should be one of: (
adjustable,
allowsDirectInteraction,
button,
disabled,
frequentUpdates,
header,
image,
key,
link,
none,
pageTurn,
plays,
search,
selected,
startsMedia,
summary,
text
)
The error appears when navigating to the stack, and the stack appears as normal. It only pops up on ios and I have no issues at all when using android. I am also following the bare react-native workflow due to limitations of the library I am using, thus no expo support.
The relevant dependencies on my package.json is as follows:
{
"dependencies": {
"#react-navigation/material-bottom-tabs": "^6.2.4",
"#react-navigation/native": "^6.0.13",
"#react-navigation/native-stack": "^6.9.1",
"#react-navigation/stack": "^6.3.2",
"react": "17.0.2",
"react-native": "0.65.1",
"react-native-gesture-handler": "^2.7.1",
"react-native-paper": "^4.12.5",
"react-native-safe-area-context": "^4.4.1",
"react-native-screens": "^3.18.2",
"react-native-vector-icons": "^9.2.0",
"react-navigation-stack": "^2.10.4",
},
}
Anyone out there knows how to get rid of this error?
I've tried solutions such as the one on Invalid UIAccessibilitys 'tablist' error after installing react-native-vector-icons and running pod update on ios where i change in
/node_modules/#react-navigation/material-bottom-tabs/lib/commonjs/ views/MaterialBottomTabView.js
/node_modules/#react-navigation/material-bottom-tabs/lib/module/ views/MaterialBottomTabView.js
/node_modules/#react-navigation/material-bottom-tabs/src/views/ MaterialBottomTabView.tsx
accessibilityRole: "link"
to
accessibilityRole: "none"
but it is not working. Might also be because this example makes changes in the bottom-tabs/ folder while mine is located in material-bottom-tabs/ folder. I am also not sure where the tablist is being imported from.

Is it possible to use React Navigation with snack.expo.io?

I like to use snack.expo.io because I'm new to programming and it makes it quick and easy to manage and access what I'm working on. However, I just tried to use React Navigation and can't get it to work. I keep getting "Unable to resolve module 'react-navigation.js'. I pulled up the React Navigation snacks at https://expo.io/snacks/#react-navigation and most of those have the same error. Am I missing something?
Perhaps my initial question should have asked if there is some initialization step I'm missing. I know I have to import it with something like
import { DrawerNavigator } from 'react-navigation';
But is there a dependency I have to manually add? I thought Expo took care of that sort of thing for you, but again, I'm not super experienced with all of this.
I don't know if this is the correct way, but I managed to get past the "unable to resolve" problem. I welcome a better solution from someone more knowledgeable than myself.
It did come down to a dependency issue. Again, in the past I'm pretty sure writing the import line resulted in Snack automatically handling the appropriate dependencies, but for some reason it did not here. So in order to get the React Navigation bottom tab navigator to show up I added
"#react-navigation/bottom-tabs": "latest",
to my package.json. My import line had to adjust to
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
This came from me poking around the Tab navigation page on reactnavigation.org (https://reactnavigation.org/docs/tab-based-navigation/) Interestingly enough, that did result in Snack pulling in a couple of other dependencies on app reload. I have no clue what the # in front of react-navigation does; it's the first time I've run into it.
Just set their dependencies in package.json and it should work fine:
{
"dependencies": {
"#expo/vector-icons": "^10.0.0",
"#react-native-community/masked-view": "0.1.10",
"#react-navigation/bottom-tabs": "^5.8.0",
"#react-navigation/drawer": "^5.9.0",
"#react-navigation/material-bottom-tabs": "^5.2.16",
"#react-navigation/material-top-tabs": "^5.2.16",
"#react-navigation/native": "^5.7.3",
"#react-navigation/stack": "^5.9.0",
"react-native-paper": "^4.0.1",
"react-native-reanimated": "~1.13.0",
"react-native-safe-area-context": "3.1.4",
"react-native-gesture-handler": "~1.7.0",
"react-native-screens": "~2.10.1",
"react-native-tab-view": "^2.15.1"
}
}

react-native-firebase-mlkit textRecognizerProcessImage is not a function

After installing react native-firebase core app and mlkit. mlkit does not work and fails when I try to use the function textRecognizerProcessImage.
I followed: https://invertase.io/oss/react-native-firebase/v6/ml-vision/quick-start and additionally for ios I did an pod install and saw how mlkit was downloaded.
However, the error from above occurs on android and ios.
Does anybody have a clue?
EDIT: I am also having access to the firebase-project using google-services.jsonand googleservice-info.plist
the relevant part from my package.json. Am using newest versions for all.
(As you can see I am also using /auth and /database both of which work just fine!
"dependencies": {
"#react-native-firebase/app": "^6.0.0",
"#react-native-firebase/auth": "^6.0.0",
"#react-native-firebase/database": "^6.0.0",
"#react-native-firebase/ml-vision": "^6.0.0",
"react": "16.9.0",
"react-native": "0.61.1"
},
the firebase.json:
{
"react-native": {
"ml_vision_face_model": true,
"ml_vision_ocr_model": true,
"ml_vision_barcode_model": true,
"ml_vision_label_model": true,
"ml_vision_image_label_model": true
}
}
simple solution...
The documentation talks about
import vision from '#react-native-firebase/ml-vision';
to import the vision library. However,
vision.anyFunctionHere will not work, since it is no instance.
the solution is to use vision().anyFunctionHere (not the brackets of doom which cost me hours and a hell lot of frustration-.-)

Unable to call web3.eth.accounts.create() without remote debugger on react native app

I am building an android wallet using react-native and trying to create an account using web3.eth.accounts.create() . This works with react-native remote debugger enabled. However, when I work the same code with the debugger off, it stops working.
this is my package.json
"cryptico": "^1.0.2",
"native-base": "2.8.0",
"node-libs-browser": "2.1.0",
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-firebase": "^5.2.0",
"react-native-gesture-handler": "^1.0.12",
"react-native-scripts": "1.14.0",
"react-navigation": "^3.0.9",
"socket.io-client": "2.0.4",
"web3": "1.0.0-beta.34"
I fixed it by using ethers.js to create new ethereum wallet.
// this is specifically for react-native
import 'ethers/dist/shims';
import {ethers} from 'ethers';
// to create a ethereum wallet
let randomWallet = ethers.Wallet.createRandom();
Web3.js is really troublesome for react-native
read more here:
https://docs.ethers.io/ethers.js/html/cookbook-react.html#
this is a guide specifically designed for react-native
I've had problems using web3 inside React Native myself, so I switched to ethers.js .
It was working better inside RN and its gives you pretty much everything you will need.