I want to load custom font i my app.
I try this
Create a assets/fonts where you can find the fonts i want to use
I add rnmp in the package.json like that :
"rnmp": { "assets": ["./assets/fonts/"] }
I link like that: react-native link
Then i use my font like that :
fontFamily: "Lato-Light",
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject"
},
"dependencies": {
"expo": "^32.0.6",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-
32.0.0.tar.gz",
"react-navigation": "^3.11.0"
},
"devDependencies": {
"babel-preset-expo": "^5.0.0"
},
"rnmp": {
"assets": ["./assets/fonts/"]
},
"private": true
}
The font should be load but i get this error :
"fontFamily" "Lato-Light" is not a system font and has not been loaded through Font.loadAsync
I assume you are using expo in this project. As the error you've shown says, you just have to load the desired fonts in the app loading process.
In you App.js file, import the fonts you want to use as const, and add an async call to load them into the app. You can use the following code:
//In the import section
import {Font} from 'expo';
const Light = require('./assets/fonts/Lato-Light.ttf');
//In the componentDidMount
await Font.loadAsync({
'Lato-Light': Light
});
Note the await in the Font.loadAsync call. You have to make the componentDidMount method async (async componentDidMount() {...}) and then add await before the Font... call.
Hope this helps!
Related
The next View component after the dropdown-picker is used is visible. If we exclude the <View> and just use the <Text> component. The <Text> component is hidden. However, if we use <Text> inside <View> the component is not hidden.
I tried using zIndex but didn't work. Maybe because I didn't use it in the right place. I also tried using different background color but that too didn't work.
Here is the expo link too. https://snack.expo.dev/5-GpW2eEU8
If I add zIndex to that code, it works fine on snack and even the uploaded code from there work well in my device. However, the same code in my local machine does not work. Is it because of the react native version?
My package.json file is:
"name": "Test",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"expo": "^47.0.0",
"expo-status-bar": "~1.4.2",
"react": "18.1.0",
"react-native": "0.70.5",
"react-native-dropdown-picker": "^5.4.4"
},
"devDependencies": {
"#babel/core": "^7.19.3"
},
"private": true
}
Interestingly, it works fine with dropDownDirection='TOP'
Also, when I tried using Element Inspector, the <View> after dropdown gets hidden.
return someCondition ? ComponentForTruthyCase : ComponentFalseyCase
I'm using an expo application
with these packages installed :
react-navigation and react-native-calendar.
recently I've updated the expo-cli and SDK to 32
in Genymotion emulator everything works great,
but in my phone (MI MIX) after the google login modal appears and i login
the app crashes.
the code for the login is as follwed:
import { Google } from 'expo';
in the componentDidMount:
const result = await Google.logInAsync({
androidClientId: 'someclientid',
iosClientId: 'someclientid',
scopes: ['profile', 'email','https://www.googleapis.com/auth/calendar'],
});
package.json:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject"
},
"dependencies": {
"expo": "^32.0.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-native-calendars": "^1.172.0",
"react-navigation": "^3.11.0"
},
"devDependencies": {
"babel-preset-expo": "^5.0.0"
},
"private": true
}
any clue whata am i doing wrong?
EDIT:
it seems like it works on other android devices
I am trying to create a Form which can take user Name and email address with the help of react-native-elements but it is giving error inside render function(Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports).
I have tried to put the FormLabel, FormIput, and FormValidationMessage inside a View and Container in render function but it is giving me an error which I am unable to figure out.
import React from 'react';
import { View, StyleSheet} from "react-native";
import { FormLabel, FormInput, FormValidationMessage } from 'react-native-elements'
export default class UserDetailsInput extends React.Component {
render() {
return (
<View>
<FormLabel>Name</FormLabel>
<FormInput/>
<FormValidationMessage>Error message</FormValidationMessage>
</View>
);
}};
package.json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject"
},
"dependencies": {
"expo": "^32.0.0",
"native-base": "^2.12.1",
"react": "16.5.0",
"react-dom": "^16.8.6",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-native-elements": "^1.1.0",
"react-native-otp-inputs": "^3.0.2"
},
"devDependencies": {
"babel-preset-expo": "^5.0.0"
},
"private": true
}
I require the react-native-elements to be shown on the UI similar as shown on the docs site.
(source: github.io)
These components have been renamed or removed in React Native Elements 1.0, your imports therefore yield undefined. Please see the corresponding release notes.
I have been trying to run react-native app on expo on my android phone. I haven't been able because I am getting an error Unable to resolve "../shared/baseUrl" from "components/MenuComponent.js" on expo.
This is the folder tree of my project where you can see baseUrl and MenuComponent.js (The other js modules on components import baseUrl.js with error.):
The following is the imports section of the components/MenuComponent.js:
import React, { Component } from 'react';
import { View, FlatList } from 'react-native';
import { Tile } from 'react-native-elements';
import { connect } from 'react-redux';
import { baseUrl } from '../shared/baseUrl';
The following is the content of shared/baseUrls.js
export const baseUrl = 'http://localhost:3001/';
This is my package.json:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject"
},
"dependencies": {
"expo": "^32.0.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-native-elements": "^1.0.0-beta8",
"react-navigation": "2.0.1",
"react-redux": "5.0.7",
"redux": "4.0.0",
"redux-logger": "3.0.6",
"redux-thunk": "2.2.0"
},
"devDependencies": {
"babel-preset-expo": "^5.0.0"
},
"private": true
}
I am using those packages versions because they are the suggested on the course I am taking.
To solve the issue, I have tried
yarn cache clean
expo r -c
Clear data/cache of expo on my cellphone.
The following is the content of shared/baseUrls.js
Are you absolutely sure the paths are correct?
What happens if you move the file in the same folder temporarily and include it from there?
import { baseUrl } from './baseUrl';
I just started React Native development, installed Expo, created an app (works), installed react-navigation and tried the first StackNavigator example using the example from https://reactnavigation.org/docs/intro/. I am running npm run ios from the commandline, and using Nuclide IDE. All of which are completely new to me.
The problem is, that on running the example the screen in the iOS emulator shows this:
Instead of showing a title bar with 'Welcome' on it.
As a beginner I have no clue where to go from here. Here's my package.json:
{
"name": "rnproject",
"version": "0.1.0",
"private": true,
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-flow": "^6.23.0",
"flow-bin": "0.42.0",
"jest-expo": "~1.0.1",
"react-native-scripts": "0.0.30",
"react-test-renderer": "16.0.0-alpha.6"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js --watch"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "^17.0.0",
"react": "16.0.0-alpha.6",
"react-native": "^0.44.0",
"react-navigation": "^1.0.0-beta.11"
}
}
there's an app.json file with these contents:
{
"expo": {
"sdkVersion": "17.0.0"
}
}
I also added flow, which throws me no errors in the example code, but 115 errors in the react-navigation package. Most of them look like: identifier 'expect', could not resolve name.
In the end I found the answer here: To use the examples on reactnavigation.org in Expo XDE, you have to make some changes. Here are the changes necessary for the first example:
import Expo from 'expo'; // <--- include this line
import React from 'react';
import {
AppRegistry, // <- remove this line
Text,
} from 'react-native';
import { StackNavigator } from 'react-navigation';
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
};
render() {
return <Text>Hello, Navigation!</Text>;
}
}
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
});
// change the following line:
AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
// into:
Expo.registerRootComponent(SimpleApp);