The react native image does not appear but takes up space. It's a file on the phone's filesystem, NOT the camera roll. It's the product of react-native-image-editor.
Tried using path with and without 'file://' prefix. Works fine on android. If i take the uri from the IOS simulator and paste it into chrome the picture appears. Using picture from the web doesn't work either which makes me think it's something to do with the styling.
const ImageAnalysis = (props) => {
const windowWidth = useWindowDimensions().width;
console.log(props.source);
const imageSource = props.source;
// const imagey = require(props.source.uri);
const realPath =
Platform.OS === 'ios'
? imageSource.uri.replace('file://', '')
: imageSource.uri;
console.log(realPath);
console.log(windowWidth);
return (
<View
style={{
flex: 2,
flexDirection: 'row',
borderBottomColor: colors.BrinkPink,
// backgroundColor: colors.RoyalPurple,
borderBottomWidth: 1,
}}>
<Image
source={{uri: props.source.uri}}
resizeMode="contain"
style={{
// position: 'relative',
height: windowWidth / 3,
width: windowWidth / 3,
borderRadius: windowWidth / 3,
margin: windowWidth / 12,
alignSelf: 'center',
}}
/>
Turns out it was a bug with React Native 0.63.0 and iOS 14. Upgrading to React Native 0.63.2 fixed it.
Related
I want to build BarCode scanner with #capacitor-community/barcode-scanner, On Android it looks totally fine, it calculate proper height of the screen and put overlay button on the bottom of the page. With Iphones it doesn't work like that, each iphone shows button in other place, I tested it on iphone 8,11 and 13. On Iphone 8 button is visible on the bottom but you can see that it is cut and it is possible to scroll down, on iphone11 it is barely visible and on iphone13 it is not visible at all. Anybody knows how to set overlay button to be totally on the bottom of the page without need to scroll down?
{isScanningInProgress ? (
<>
<StyledStopScanBox>
<Button color="primary" variant="contained" size="large" onClick={stopScan}>
Stop Scan
</Button>
</StyledStopScanBox>
</>
) : (
...
)
const StyledStopScanBox = styled(Box)(({ theme }) => ({
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
position: 'absolute',
width: '100%',
top: 'calc(100vh - 75px)',
zIndex: 3,
height: 75,
backgroundColor: theme.palette.background.default
}));
I'm using a multi line TextInput in my react-native application and been stuck on this for a while. I can not get the text to be vertically aligned on IOS devices.
using textAlign='center' puts the text on IOS vertically centered... but it becomes an unwrapped never ending line.
adding multiline={true} negates the vertically aligned text in IOS and puts it at the top of the input.
<TextInput
style={{
width: wp('80%'),
height: hp('25%'),
borderWidth: 1,
borderRadius: 10,
fontSize: RF(3),
}}
textAlign={'center'}
multiline={true}
onChangeText={entry => this.setState({entry})}
value={this.state.entry}
/>
I would like the behavior to be like android in that it shows the placeholder text vertically and horizontally centered and when user inputs more text it starts creating multi lines if needed but always vertically and horizontally centered.
Please see image with android version on left and IOS on right.
Android on left, IOS on right
try adding textAlignVertical={"center"} to textInput's props
Have you tried wrapping the TextInput in a View?
<View style={{ alignItems: 'center', justifyContent: 'center' }}>
<TextInput
style={{
width: wp('80%'),
height: hp('25%'),
borderWidth: 1,
borderRadius: 10,
fontSize: RF(3),
}}
textAlign={'center'}
multiline={true}
onChangeText={entry => this.setState({entry})}
value={this.state.entry}
/>
</View>
Add the attribute paddingTop to your TextInput in your XML file.
How can I underline placeholder in iOS in React Native? I can underline whole TextInput (not placeholder) by:
borderBottomWidth: 1,
borderBottomColor: '#B8B8B8',
I would like to underline only placeholder of TextInput, not TextInput
I have a little workaround for you. As soon as you start typing, the underline gets removed.
Demo
Explanation
I applied the borderBottomWidth and borderBottomColor to the parent view, because you probably don't want to use multiline. If you want to use a mulitine TextInput you could apply those styles directly to the Textinput, as mentioned in the docs.
Note that some props are only available with multiline={true/false}.
Additionally, border styles that apply to only one side of the element
(e.g., borderBottomColor, borderLeftWidth, etc.) will not be applied
if multiline=false. To achieve the same effect, you can wrap your
TextInput in a View
As soon as the user has typed (the text length is greater than 0) something, this.setState({ active: true }) gets fired. After that the conditional rendering takes place here:
borderBottomColor: this.state.active === false ? 'red' : 'transparent' // hide color, when text is present
width: this.state.active === false ? scaledWidth : 100 // increase width to 100. Value is just a placeholder, use whatever you like
Complete Code
// helper function to scale font size and placeholder width.
scale = (fontSize) => {
const screenWidth = Dimensions.get('window').width;
const ratio = fontSize / 375; // get ratio based on your standard scale, here: width of iphone 7
const newSize = Math.round(ratio * screenWidth);
return newSize;
}
render() {
// you probably have to play around with those standard values
const scaledFontSize = this.scale(22);
const scaledWidth = this.scale(25);
return (
<View style={{ marginTop: 50, flex: 1, alignItems: 'flex-end' }}>
<View style={{ borderBottomWidth: 2, borderBottomColor: this.state.active === false ? 'red' : 'transparent', width: this.state.active === false ? scaledWidth : 100 }}>
<TextInput
style={{ height: 30, textAlign: 'right', fontSize: scaledFontSize }}
onChangeText={(text) => text.length > 0 ? this.setState({ active: true }) : this.setState({ active: false })}
placeholder={'10'}
//multiline
/>
</View>
</View>
)
}
I want to make a grid of elements with a separator with fixed width of 1 "pixel". Like in a Photo app grid for iOS.
For item width in a FlatList I use flex style, because I can not predict their width on different screens.
Code example: https://snack.expo.io/ryK_zPmEM
But on my iPhone 7 Plus (real device) i have got this result:
The separator between the second and the third cell has a style marginLeft: 1 but looks wider than the other two separators.
And this is a screenshot of the simulator for iPhone 5S:
The result is the opposite. You can also notice that the thickness of the separator between the rows is also different.
The question is: what value should be set for margin style so that separator looked the same for all screen sizes and did not change its width between the cells int the row?
Or perhaps I need to calculate the exact value for the width of the cell instead of using flex: 1?
Full code example:
const WINDOW_WIDTH = Dimensions.get('window').width
const ITEMS_PER_ROW = 4
const MARGIN_WIDTH = 1
const TOTAL_MARGIN_WIDTH = MARGIN_WIDTH * (ITEMS_PER_ROW - 1)
const CELL_SIZE = (WINDOW_WIDTH - TOTAL_MARGIN_WIDTH) / ITEMS_PER_ROW
const listData = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
export default class App extends Component {
_renderItem = ({item, index}) => {
return (
<View style={[styles.cell, (index % 4 !== 0) ? styles.cellMargin : {}]}>
<Text>{item}</Text>
</View>
)
}
render() {
return (
<View style={styles.container}>
<FlatList
contentContainerStyle={styles.list}
columnWrapperStyle={styles.listColumn}
data={listData}
numColumns={ITEMS_PER_ROW}
keyExtractor={i => i}
renderItem={item => this._renderItem(item)}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'red',
},
list: {
backgroundColor: 'cyan',
flex: 1,
},
listColumn: {
marginTop: 1,
height: CELL_SIZE,
backgroundColor: 'white',
},
cell: {
backgroundColor: 'green',
flex: 1,
},
cellMargin: {
marginLeft: MARGIN_WIDTH,
}
});
I'm attempting to put a floating button over a ListView in my React-Native application on iOS. The appearance is great, but the functionality of my TouchableHighlight is not so great...
<TouchableHighlight
onPress={() => {
this.myAction()
}}>
<View style={styles.floatingCameraButton}>
<Image source={camera_icon} style={styles.cameraIcon}/>
</View>
</TouchableHighlight>
That's my code for the button, and here are my stylings:
floatingCameraButton: {
height: 80,
width: 80,
borderRadius: 40,
backgroundColor: '#aa2222',
position: 'absolute',
bottom: 20,
right: 20,
shadowColor: '#000000',
shadowOpacity: 0.8,
shadowRadius: 2,
shadowOffset: {
height: 5,
width: 5
},
},
For some reason, when the button is touched on the lower portion of the screen, the touch fails to register on the button.
I've tested making the button taller and also moving in up, and both of those are solutions, but not ones I am interested in.
My assumption is that somehow React-Native is masking my touches that occur where the iOS native Tab Bar would be (meaning the bottom 50px). However, I do not have a Tab Bar on the screen, nor have I implemented one. I do have a Navigator that is wrapping the view which my button is in, not sure if that could be the culprit.
Any ideas or help to get my TouchableHighlight to be touchable on the bottom 50px of the screen would be very helpful.
Try applying your styles to the TouchableHighlight itself.
<TouchableHighlight
style={styles.floatingCameraButton}
onPress={() => this.myAction()}>
<Image source={camera_icon} style={styles.cameraIcon}/>
</TouchableHighlight>