creativetimofficial / ct-argon-pro-react-native

Premium React Native App Template with Argon Design
https://www.creative-tim.com/product/argon-pro-react-native
9 stars 7 forks source link

fontLoading Issue with react native #2

Closed kc9pos closed 4 years ago

kc9pos commented 4 years ago

Screenshot_1575862958

Good afternoon I bought the react native pro argon app and I keep getting held up by this error the code looks to be following the correct recommended documentation on loading custom fonts but no matter what I try I cannot resolve this issues. It is something that happens even with a fresh download from your website what are my options thank you. The issues happens with all the fonts within the custom font section seems very random.

import React from 'react'; import { Image } from 'react-native'; import { AppLoading } from 'expo'; import * as Font from 'expo-font'; import { Asset } from 'expo-asset'; import { Block, GalioProvider } from 'galio-framework';

import Screens from './navigation/Screens'; import { Images, articles, argonTheme } from './constants';

// cache app images const assetImages = [ Images.Onboarding, Images.LogoOnboarding, Images.Logo, Images.Pro, Images.ArgonLogo, Images.iOSLogo, Images.androidLogo, ];

// cache product images articles.map(article => assetImages.push(article.image));

function cacheImages(images) { return images.map(image => { if (typeof image === 'string') { return Image.prefetch(image); } else { return Asset.fromModule(image).downloadAsync(); } }); }

export default class App extends React.Component { state = { fontLoaded: false, isLoadingComplete: false,

}

async componentDidMount() { try { Font.loadAsync({ 'open-sans-regular': require('./assets/font/OpenSans-Regular.ttf'), 'open-sans-light': require('./assets/font/OpenSans-Light.ttf'), 'open-sans-bold': require('./assets/font/OpenSans-Bold.ttf'), }); this.setState({ fontLoaded: true }); } catch (error) { console.log('error loading icon fonts', error); } }

render() { if(!this.state.isLoadingComplete) { return ( <AppLoading startAsync={this._loadResourcesAsync} onError={this._handleLoadingError} onFinish={this._handleFinishLoading} /> ); } else { return (

  );
}

}

_loadResourcesAsync = async () => { return Promise.all([ ...cacheImages(assetImages), ]); };

_handleLoadingError = error => { // In this case, you might want to report the error to your error // reporting service, for example Sentry console.warn(error); };

_handleFinishLoading = () => { if(this.state.fontLoaded) { this.setState({ isLoadingComplete: true }); } };

}

palingheorghe commented 4 years ago

Hi @kc9pos ! Thank you for being interested in our products. I've tested the app and I don't have any problems with the font selection. The problem must be with your configuration. You should remove node_modules, package-lock.json and .expo and re-use the npm install command in order to install all the depepndencies. If the product still isn't working after following these steps then you could try updating expo-cli.

Thanks, Alin

kc9pos commented 4 years ago

Screenshot_1576042412

so I downloaded your free react native templates

here is my package.json from the argon-pro app { "name": "argon-pro-react-native", "version": "1.2.0", "description": "Argon Pro React Native, based on Argon Design System. Coded by Creative Tim", "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "eject": "expo eject" }, "repository": { "type": "git", "url": "git+https://github.com/creativetimofficial/argon-pro-react-native.git" }, "dependencies": { "expo": "^35.0.0", "expo-asset": "~7.0.0", "expo-cli": "^3.10.2", "expo-font": "~7.0.0", "galio-framework": "^0.6.3", "prop-types": "^15.7.2", "react": "16.8.3", "react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz", "react-native-gesture-handler": "~1.3.0", "react-native-modal-dropdown": "^0.6.2", "react-navigation": "^3.11.0" }, "devDependencies": { "babel-preset-expo": "^7.0.0" }, "keywords": [ "argon react native", "argon design system", "argon app react native", "argon iOS", "react native iOS", "creative tim", "argon Android", "react native ui kit", "react native expo", "freebie", "react native argon design", "react native galio", "galio argon pro", "galio react native free app", "argon expo react native", "react native ui template" ], "author": "Creative Tim hello@creative-tim.com (https://www.creative-tim.com/)", "bugs": { "url": "https://github.com/creativetimofficial/ct-argon-pro-react-native/issues" }, "homepage": "https://demos.creative-tim.com/argon-pro-react-native" }

palingheorghe commented 4 years ago

@kc9pos I can guarantee you the product has no issues with the font loading function. The thing with the fonts and Expo is that mostly the font problem has something to do with cache or expo-cli. The loading is done correctly inside the App.js file. Could you try and verify your local expo-cli package version? Also you should try and update it if it's not already on the latest version.

Thanks, Alin 🤙🏽

jorgeluis91x commented 4 years ago

I have the same problem, I got the premium but I have some problem with fonts, What can I do, help me please

jorgeluis91x commented 4 years ago

IMG_2995

palingheorghe commented 4 years ago

Hi @jorgeluis91x ! Thank you for your interest in our product, as I've explained earlier this is a cache problem and not a problem with our product. You could try deleted node_modules, package-lock.json and .expo. After that reinstall the packages via npm install and restart the Expo server using the following command expo r -c .

roblimab commented 4 years ago

Hi @jorgeluis91x ! Thank you for your interest in our product, as I've explained earlier this is a cache problem and not a problem with our product. You could try deleted node_modules, package-lock.json and .expo. After that reinstall the packages via npm install and restart the Expo server using the following command expo r -c .

Hi. I did just that and I am still facing this problem. I bought the premium version. Any other suggestions?

async componentDidMount() { Font.loadAsync({ 'open-sans-regular': require('./assets/font/OpenSans-Regular.ttf'), 'open-sans-light': require('./assets/font/OpenSans-Light.ttf'), 'open-sans-bold': require('./assets/font/OpenSans-Bold.ttf'), }); this.setState({ fontLoaded: true }); }

And if I put an await in Font.loadAsync it takes forever...

palingheorghe commented 4 years ago

Hi @roblimab ! Thanks for writing us! Could you please specify what error you get? If it's the same error, the explanaition I have in the earlier posts should be working because that error has nothing to do with the implementation. Please let me know how is that working out for you

Thanks, Alin

palingheorghe commented 4 years ago

closed due to inactivity. as stated before the fontLoading error is caused by cache and reinstalling all packages and running the app with expo r -c solved the issue.

deepti-nucleusteq commented 4 years ago

I found that if I comment out this line articles.map(article => assetImages.push(article.image)); from App.js it starts throwing this error. Could you please check and let me know how do I remove those un-necessary download of images to my app.

mahatch commented 1 year ago

you can find the resolution here: https://github.com/creativetimofficial/ct-argon-pro-react-native/issues/7