Problem: The height of webview doesn't reduce when I open up the keyborad on IOS
I used a KeyboardAvoidingView wrap my Webview like this
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
style={isKeyboardOpen ? {
backgroundColor: 'rgba(0,0,0,0.3)',
position: 'absolute',
left: webViewConfig.x,
top: webViewConfig.show ? y : deviceHeight,
width: deviceWidth - webViewConfig.x,
height: deviceHeight - y - keyboardHeight,
} : {
backgroundColor: 'rgba(0,0,0,0.3)',
position: 'absolute',
left: webViewConfig.x,
top: webViewConfig.show ? y : deviceHeight,
width: deviceWidth - webViewConfig.x,
height:
deviceHeight - y
}}
>
// webivew here
</KeyboardAvoidingView>
I even make the height of KeyboardAvoidingView is dynamically change when the keyboard is hidden/appeared.
Please check the image below. I'd like to make the red section is dissapeared. Or at least make the content of webview fit into the container's space (which is KeyboardAvoidingView component) and make it unable to scroll down.
Screenshots/Videos:
I add style={{ backgroundColor: 'red' }} into Weview. As you can see that the webview's content is shirnked as exepected but the red bacground still appear.
Environment:
OS: IOS
OS version: 15.4.1
react-native version: 0.64.2
react-native-webview version: 11.2.3
In my case. I need to prevent the webview from scrolling. There is a property called scrollEnabled of the WebView component that does that. The codes will look like this
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
style={{
backgroundColor: 'rgba(0,0,0,0.3)',
position: 'absolute',
left: webViewConfig.x,
top: webViewConfig.show ? y : deviceHeight,
width: deviceWidth - webViewConfig.x,
height: deviceHeight - y
}}
>
<Webview
// other properties
scrollEnabled={false} // -> set this to false
/>
</KeyboardAvoidingView>
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 currently trying to set a full background image on my login view.
I've used the following code to do so but noticed that Iphone 11 have like a white bar at the bottom and top of the phone. Is this something that can't be overlapped since it's like the navigation?
const Background = styled.ImageBackground`
padding:20px;
justify-content:center;
width:100%;
height:100%;
`
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
enter image description here
return <SafeAreaView style={styles.container}><Background source={require('../../assets/images/background-cover.jpg')}>
<CoverLogo width={100} height={100} color={Colors.White} />
<Introduction loop={false}>
<TextHeading text={`#test`} />
<TextPage text={`Btest2`} />
<TextPage text={`Ttest3`} />
<TextPage text={`test4 Sign up !`} />
</Background>
</SafeAreaView>
I'm not sure if this will help with the bottom of the screen, but for the top you can try and set your header style in navigationOptions like so if using react navigation
headerStyle: {
backgroundColor: 'transparent',
position: 'absolute',
top: 0,
left: 0,
right: 0,
borderBottomWidth: 0 // removes the border on the bottom
}
If you follow the SafeArea advice also given in the other answer, then this may be of help too https://reactnavigation.org/docs/handling-safe-area/
Try using :
SafeArea as a parent view, with flex:1
Or maybe have a function to check for iPhone 11/ iPhoneX like that:
isIphoneX: () => {
const dimen = Dimensions.get('window');
const deviceModel = DeviceInfo.getModel();
return (
deviceModel === 'iPhone X' ||
(Platform.OS === 'ios' &&
!Platform.isPad &&
!Platform.isTVOS &&
(dimen.height === 812 ||
dimen.width === 812 ||
dimen.height === 896 ||
dimen.width === 896))
);
},
iPhones Specs
your issue lies in your use of
<SafeAreaView> tag which limits the use of the screen space in ios devices below the notch and just above the lower edge of the screen. The use of SafeAreaView is only visible in the effects only on ios devices.
To resolve your issue I would suggest using the tag <View> instead of <SafeAreaView>
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.
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'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>