react-native-i18n: undefined is not an object (evaluating 'RNI18n.languages') - javascript

So, I want to setup multilanguage support for my app. On the base of react-native. However, when looking at i18n solution it pops up an error:
I followed the installation step on https://github.com/AlexanderZaytsev/react-native-i18n, everything installed and got linked ok, without errors. Tried to setup most basic sample on completely new project. The "App.js" file looks as follows:
import I18n from 'react-native-i18n'
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Text>{I18n.t('greeting')}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
I18n.fallbacks = true
I18n.translations = {
en: {
greeting: 'Hi!'
},
fr: {
greeting: 'Bonjour!'
}
}
Whenever I try to run it on emulator, the systems pops that error. Driving me nuts at this point. Any known solutions I have missed at this point?

In your project, execute:
$ react-native link
and reboot.
See:
https://github.com/AlexanderZaytsev/react-native-i18n#manual-setup
https://facebook.github.io/react-native/docs/linking-libraries-ios.html#step-2

Related

Error undefined is not an object (evaluating ‘_expo.Constants.statusBarHeight’)

I'm getting an error for using paddingTop: Constants.statusBarHeight
I used import { Consants } from "expo";
I copied this code from my previous project that i made during university but now this doesnt seem to work
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#3498db",
justifyContent: "center",
paddingTop: Constants.statusBarHeight
},
Don't use these marks { and }
just call like this:
import Constants from "expo-constants";
Run the following first
sh
yarn install expo-constants
then the following
import Constants to your App.js
import Constants from "expo-constants";

How do i use custom fonts in navigation tab in react native + expo?

I can load and render custom fonts for text in general, but when i try to specify the font Family for my navigation bar, i get an error: "fontfamily 'poetsenone' is not a system font and has not been loaded through Font.Loadsync.
i've loaded the font in my root comopnent # app.js using Font.Loadasync.
// homescreen.js:
static navigationOptions = {
title: 'Scan',
tabBarOptions: {
labelStyle: {
fontSize: 20,
fontFamily: "poetsenone"
},
tabStyle: {
},
style: {
marginTop: 23,
backgroundColor: '#423D3D',
},
}
};
//app.js
export default class App extends React.Component {
componentDidMount() {
Font.loadAsync({
'poetsenone': require('./assets/fonts/poetsenone.ttf')
});
}
render() {
return (
<AppContainer />
);
}
}
Isn't app.js typically the top-level component? what's going on?
Remove the quotes around 'poetsenone' in loadAsync and it should work.

react-native: share api passing base64 string instead of image to WhatsApp

Hey i am struggling with sharing an base64 image via WhatsApp. In iOS also Android the actual base 64 is been shared instead of the image.
If I use iMessage or Email (iOS) the base64 images is been converted and displayed as expected. In Android using Email for sharing displays just the base64 string. Did anyone else face the same issue?
I am using react-native ~0.55.2
react-native Share API
import React, { Component } from 'react';
import {Image, Text, StyleSheet, View, Share, Button} from 'react-native';
class ShareClass extends Component {
onClick() {
Share.share({
message: REACT_ICON, //for whats app
url: REACT_ICON, // for other applications
title: 'Wow, did you see that?'
}, {
// Android only:
dialogTitle: 'Share BAM goodness',
})
}
render() {
return (
<View style={styles.container}>
<Button
title ="Testing the Share Button"
onPress = {this.onClick}>
</Button>
<Text>Testing the display of base64 image</Text>
<Image source = {{uri:REACT_ICON, width:100, height: 100}} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
}
});
const REACT_ICON = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAd4klEQVR42u1dCZgU1bUuN/KyuDwxL2I0UWM0i9uToMaocUmiRn2+p7i9aNxjVNyIaFAUEZco+tQkLggqPlEU1xh35KGoiDgsM91dVT0DIiKCC4yiw0zPVNV95/y3WKbrVvXt7qqambbv99U3Q9NTdesu557lP/8xjHqrt3qrt3qrt3qrt3qrt3qrt3qrt5RaVvQzMoXdDEsMN2zximF58+nnMsP2PqXPPqLf3zMsdzb9nGiYzlDDFL80zLYBhhAb9Lp3scXG9D570s+LqM+PU/9z9D4f089VdHXR5wW6VtC75Q3TfYTe5ffG3PZte+W7pNIWi6/TIOxPg3UPDdByGhyPLhFxdWJQbXEbDfSRdO1g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EQODIFDRITVuEyiyWuBxJH+yR7POQr3qrt3qrt3qrt3qrt3qrt3qrt3rrQ+3/ATxSgu3z5tTfAAAAAElFTkSuQmCC';
export default ShareClass
I am not sure how it will work with inbuilt Share functionality added by react-native. But using react-native-share worked for me.
I have found a working workaround for this problem. Currently, I also use it in one of my applications. You can directly plug and play the below onClick function on a button press.
RNFS.downloadFile, downloads the remote image using URL and save it to a path.
RNFS.readFile, converts the locally saved file data to base64 which is supported directly by Whatsapp and other applications.
import Share from 'react-native-share';
import RNFS from 'react-native-fs';
async onClick(url, id){
const path = `${RNFS.DocumentDirectoryPath}/${id}.jpg`;
await RNFS.downloadFile({ fromUrl: url, toFile: `file://${path}` }).promise
.then((res) => {
return res;
})
.catch((err) => {
return err;
});
RNFS.readFile(`file://${path}`, 'base64').then((res) => {
let shareOptionsUrl = {
title: 'My Application',
message: 'Use my application',
url: `data:image/jpeg;base64,${res}`, // use image/jpeg instead of image/jpg
subject: 'Share information from your application'
};
Share.open(shareOptionsUrl);
})
}
Url is the image remote URL and id is some unique identifier for that image.

How to allow react-native to enable support for JSX (extension) files

React Native app fails to resolve components.
I am trying to import & render Test.jsx inside of App.js.
I get the following error-
error: bundling failed: Error: Unable to resolve module `./screens/Test` from App.js`:
The module `./screens/Test` could not be found from App.js. Indeed, none of these files exist
Project Manager(or rather files) look like this-
Code of Test.js-
import React, { Component } from 'react';
import {View, Text, StyleSheet} from 'react-native'
export default class Test extends Component {
render() {
return (
<View style={styles.container}>
<Text>Hello World?</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
}
});
Code of App.js-
/**
* Sample React Native App
* https://github.com/facebook/react-native
* #flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import Test from "./screens/Test";
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<View style={styles.container}>
<Test />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
I've literally tried every solution mentioned - react-native#4968 and none of them seem to work.
I've also referred to this, but, the solution is for css and nowhere close to what would fix this issue.
I've looked at lot more issues and SO's with no clue what else I have to do. I've also created a new project(screenshot and code is from the new project).
What am I missing?
UPDATE:
I realised that the issue was because I have .jsx extension. Imports are working fine for .js file. Any pointers on how to enable the project to accept .jsx for imports?
update: for RN >0.59 as #RedGaint pointed in https://stackoverflow.com/a/55134051/8034782 you need to configure metro.config.js in the root level.
module.exports = {
resolver: {
/* resolver options */
sourceExts: ['jsx','js'] //add here
},
transformer: {
/* transformer options */
},
serializer: {
/* serializer options */
},
server: {
/* server options */
}
/* general options */
};
For RN < 0.57:
Inside of the root of your project add a file named rn-cli.config.js and place the following code into it.
// ./rn-cli.config.js
module.exports = {
/// #description Allows you to enable support for JSX files
/// The `index.js` file in the root of your project has to be `.js`.
getSourceExts: () => [ 'jsx', 'js' ],
}
For RN > 0.57:
module.exports = {
resolver: {
sourceExts: ['jsx', 'js'],
},
};
for more reference look into this there is already an issue opened:
https://github.com/facebook/react-native/pull/5233#issuecomment-382083236
I am using react-native 0.59 and metro-react-native-babel-preset": "^0.53.0",.
The ./rn-cli.config.js file no longer works in the IOS release build. RN 0.59 requires a config file called metro.config.js in the root level. I have to use it to enable JSX support instead of rn-cli.config.js. Check out the documentation for the config file: https://facebook.github.io/metro/docs/en/configuration.html
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* #format
*/
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
resolver: {
sourceExts: ['jsx','js', 'json', 'ts', 'tsx']
}
};
It seems that the config schema was changed in 0.57 version: #248
Try this:
// ./rn-cli.config.js
module.exports = {
resolver: {
sourceExts: ['jsx', 'js'],
},
};
If someone doesn't want to load the default config and spread it, then they can simply use this
In metro.config.js
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
resolver: {
sourceExts: [
'js', // note this has to be defined first or you get an error
'json',
'jsx',
'mjs',
// required because the react-native cli ignores `resolverMainFields`
'ts',
'tsx',
],
},
};
This works in ReactNative v0.63
// metro.config.js
const { getDefaultConfig } = require('metro-config');
module.exports = (async () => {
const { resolver: { sourceExts } } = await getDefaultConfig();
return { resolver: { sourceExts: [...sourceExts, 'jsx'] } };
})();
Note: This approach will not overwrite existing settings.

is it possible to separate var styles = StyleSheet.create from React.component into different script in react native?

is it possible to separate var styles = StyleSheet.create from React.component into different script in react native?
that's possible. just create a js file with this pattern:
'use strict';
var React = require('react-native');
var myStyles = React.StyleSheet.create({
style1: { },
style2: { }
)}
module.exports = myStyles;
then in your component js use require to use that style sheet e.g. assuming your style js file is named phongyewtong.js
var s = require('../the/path/to/phongyewtong');
usage:
<View style = {s.style1} />
Both of the below links explain very well how to move styles out of your 'structural' code :
https://hackernoon.com/manage-react-native-project-folder-structure-and-simplify-the-code-c98da77ef792
https://medium.com/the-react-native-log/tips-for-styling-your-react-native-apps-3f61608655eb
Basically (copying code snippet from above link #2) have your styles in separate JS, say text.js file :
const text = StyleSheet.create({
p: {
color: 'black',
fontFamily: 'Open Sans',
fontSize: 14,
},
title: {
fontWeight: 'bold',
color: 'black',
fontFamily: 'Open Sans',
fontSize: 20,
}
});
export default text;
In React component, you can simply import this text style, and use it directly
<Text style={text.p}>settings</Text>
Hope this helps.
In a more recent React Version (0.31) I used this code:
import React, { Component, PropTypes } from 'react';
import { StyleSheet } from 'react-native';
var styles = StyleSheet.create({
...
});
module.exports = styles;

Categories