I'm trying to fit my text inside available area and my constraints are something like this:
- Text should not overflow,
- Text must scales up inside all available view,
- Words should not broken into characters and goes to next line sentences can be,
- When I'm using flex inside parent view text should not expand view more than screen width horizontally.
Here is my code snippet:
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import { Font } from "expo";
import Lorem from "./src/helpers/lorem-ipsum-gen";
export default class App extends React.Component {
constructor() {
super()
this.state = {
fontLoaded: false,
};
}
//theboldfont.ttf
async componentWillMount() {
await Font.loadAsync({
"akzidenz-grotesk-bq-bold": require("./assets/fonts/AkzidenzGrotesk_BQ_Bold.otf"),
});
this.setState({ fontLoaded: true });
}
render() {
let loremText = new Lorem().generate(20)
return (
<View style={styles.container}>
<View>
<View style={{ flex: 0.37 }} > </View>
<View style={{ flex: 0.25, backgroundColor: "red" }} >
<View >
{
this.state.fontLoaded ? (<Text
style={{ fontFamily: "akzidenz-grotesk-bq-bold", fontSize: 50 }}
adjustsFontSizeToFit={true}
>
{loremText}
</Text>) : null
}
</View>
</View>
<View style={{ flex: 0.38 }} >
<Text>
{loremText}
</Text>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
And result of it:
What I've tried to achieve my goal:
- I thought it's related with custom font & changed to default font(Not worked)
- In some github issues people wrote adjustsFontSizeToFit={true} inside text style prop (Not worked)
- I tried allowFontScaling (Not worked)
- Removed fontsize (Not worked)
- Removed flex and set static width and height to view (Not worked)
- Combinations of all steps above (Not worked)