I am at a loss, my image is huge and just goes off the screen and you can't see it. It's just a ScrollView that shows a bunch of scans of pages from a book. I can vertically scroll and see the rest of the image but I just cannot get it to be contained within the view. I'm using iOS, My code is below
import React from 'react';
import { WebView } from 'react-native-webview'
import { ScrollView, Image, View, StyleSheet, Dimensions } from 'react-native';
const StandardizationScreen = ({ navigation }) => {
return (
<ScrollView style={{flex: 1}} contentContainerStyle={{alignItems: "center"}}>
<View style={{flex: 1}}><Image style={styles.image} source={require('../assets/standardization/3982243bbc574ccbad697528ff26f605-52.png')}/></View>
</ScrollView>
)
}
const win = Dimensions.get('window');
const styles = StyleSheet.create({
image: {
width: win.width
}
})
export default StandardizationScreen;
You can use resizeMode = 'contain'
const styles = StyleSheet.create({
image: {
width: win.width,
resizeMode:'contain'
}
})
Related
I'm currently having a problem with the clickable size of a reusable button which includes an icon and text. When I run this code it seems like the entire row becomes clickable when I only want the icon and text to become clickable. Does anyone know how to solve this problem? Thanks
App.js
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import IconTextButton from './components/iconTextButton';
export default function App() {
return (
<View style={styles.container}>
<Text style={{marginTop: 100}}>My First React App! Sike </Text>
<IconTextButton iconFont="ionicons" iconName="pencil" iconSize={25} text="Add Items"/>
</View>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'powderblue',
},
});
iconTextButton.js
import React from 'react';
import { StyleSheet, TouchableOpacity, Text, View } from 'react-native';
import Ionicon from 'react-native-vector-icons/Ionicons';
export default function IconTextButton({ iconFont, iconName, iconSize, text, onPress }) {
const getIconFont = (iconFont) => {
switch (iconFont) {
case "ionicons":
return Ionicon;
}
};
const FontIcon = getIconFont(iconFont);
return (
<TouchableOpacity onPress={onPress} style={styles(iconSize).container>
<FontIcon name={iconName} size={iconSize} style={styles(iconSize).buttonIcon}>
<Text style={styles(iconSize).buttonText}>{text}</Text>
</FontIcon>
</TouchableOpacity>
)
}
const styles = (size) => StyleSheet.create({
container: {
backgroundColor: 'pink',
},
buttonIcon: {
backgroundColor: 'yellow',
width: size,
},
buttonText: {
backgroundColor: 'green'
},
})
Along with the code I've tried, I've also tried to keep and as seperate contents whilst adding a flexDirection: 'row' inside styles.container. This keeps the contents in the same line but it still makes the whole row clickable. I've also tried putting everything in a and moving the styles.container to the component and adding a height: size into styles.container. This makes the clickable component limited however, the component is hidden underneath due to the restricted height. I have also tried simply just using instead of making a reusable const that its an input. The same thing applies.
You can wrap your Icon and Text Component in a View component and then wrap it inside a TouchableOpacity Component
Try this or do something like this :
import React from 'react';
import { StyleSheet, TouchableOpacity, Text, View } from 'react-native';
import Ionicon from 'react-native-vector-icons/Ionicons';
export default function IconTextButton({ iconFont, iconName, iconSize, text, onPress }) {
const getIconFont = (iconFont) => {
switch (iconFont) {
case "ionicons":
return Ionicon;
}
};
const FontIcon = getIconFont(iconFont);
return (
<TouchableOpacity onPress={onPress} style={styles(iconSize).container}>
<View style={styles(iconSize).iconTextContainer}>
<FontIcon name={iconName} size={iconSize} style={styles(iconSize).buttonIcon} />
<Text style={styles(iconSize).buttonText}>{text}</Text>
</View>
</TouchableOpacity>
)
}
const styles = (size) => StyleSheet.create({
container: {
backgroundColor: 'pink',
},
iconTextContainer: {
flexDirection: 'row',
alignItems: 'center',
},
buttonIcon: {
backgroundColor: 'yellow',
width: size,
},
buttonText: {
backgroundColor: 'green'
},
})
I want to create a View bigger than the screen with react native directly to works in android and ios, why do i want to create it? because i want to create a swipe at the item on the list
import React from "react";
import { View, Text } from "react-native";
const ViewBoxesWithColorAndText = () => {
return (
<View>
<View style={{ backgroundColor: "red", flex: 0.5 }} />
<Text>Hello World!</Text>
</View>
);
};
export default ViewBoxesWithColorAndText;
Here are the screen dimensions.
import { Dimensions } from 'react-native'
const Window = Dimensions.get('window')
const Screen = Dimensions.get('screen')
const WIDTH = Screen.width
const HEIGHT = Screen.height
const FONT_SCALE = Window.fontScale
const SCREEN_SCALE = Window.scale
I hope, these what you wanted.
import { StyleSheet, Text, View } from 'react-native'
import React from 'react'
const Title = () => {
return (
<View style={styles.container}>
<Text styles={styles.title}>Quizzier</Text>
</View>
)
}
export default Title
const styles = StyleSheet.create({
title: {
fontSize:80,
fontWeight:"600",
},
container:{
paddingVertical:16,
justifyContent:"center",
}
})
Explain:
I am creating quiz app watching video tutorial from youtube. Everything works just fine in video but it was IOS, mine is Android.
Problem: fontSize is not working.
The prop is style not styles
const Title = () => {
return (
<View style={styles.container}>
<Text style={styles.title}>Quizzier</Text>
</View>
)
}
How to use useWindowDimensions in Stylesheet. It always works only inside the function. I want to get screen height and width using useWindowDimensions inside the stylesheet in react native.
useWindowDimensions is a hook, so we just can use it inside a functional component. Maybe there are other ways, but I'd like to suggest you something like that:
import React from 'react';
import { View, Text, StyleSheet, useWindowDimensions } from 'react-native';
const Main = () => {
const { styles } = useStyle();
return (
<View style={styles.container}>
<Text>Dimension Properties inside StyleSheet{'\n'}</Text>
<Text>Heigth: {styles.container.height.toString()}</Text>
<Text>Width: {styles.container.width.toString()}</Text>
</View>
)
}
const useStyle = () => {
const dimensions = useWindowDimensions();
console.log('Logging dimensions', dimensions)
const styles = StyleSheet.create({
container: {
height: dimensions.height,
width: dimensions.width,
justifyContent: 'center',
alignItems: 'center',
},
})
return { styles }
}
export { Main }
Please, let me know if this helped you.
I'm trying to make simple messaging bubbles like this:
Desired outcome Image
however, I can't figure out how to make the red background wrap the text only. I keep gutting this:
Code output Image
import React, { Component } from 'react';
import { Container, Header, Content, Button, Left, Icon, Body, Title, Right } from 'native-base';
import { View, StyleSheet, TextInput, ScrollView, ListView, Text } from 'react-native';
export default class App extends Component {
constructor(props) {
super(props);
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {text: '', dataSource: ds.cloneWithRows(['hi', 'My Name is adam']),};
}
render() {
return (
<Container style={styles.container}>
<ListView
dataSource={this.state.dataSource}
style={styles.list}
renderRow={(rowData) =>
<Text style={styles.senderMessageText}>
{rowData}
</Text>
}
/>
</Container>
);
}
}
const styles = StyleSheet.create({
container:{
backgroundColor: 'green'
},
list:{
backgroundColor:'blue'
},
senderMessageText: {
backgroundColor:'red',
padding: 8,
marginTop: 10
}
});
I have tried everything.. Please help
Try this solution:
React Native: "Auto" width for text node
It suggests to use the alignSelf property. Use alignSelf: 'flex-start'
PS: ListView is deprecated.Use FlatList instead. It has better performance for large data