ScrollView rounded corners - javascript

I made a custom Image swiper withe ScrollView in React Native, but it looks bad when images with rounded corners move. Is there any way to round the corners of the ScrollView?
Those are my ScrollView styles:
style={{
flexDirection: 'row', alignSelf: 'center',
width: this.state.imageWidth,
borderRadius: 20,
}}

ScrollView also inherits styles from ViewStyles so you can pass borderRadius: 20 to it.

Related

React Native - Keyboard covers bottom part of the input

In my app keyboard covers only bottom part of the text input. I have tried several ways to solve this by changing styles by adding padding or margin, and also KeyboardAvoidingView didn't help.
Another problem is that keyboard shifts the whole screen and header becomes invisible as it goes above.
Edit: It works fine on IOS devices.
How can I fix these problems?
Thanks
Code:
<>
<CustomHeader title={item.title}
leftChild={<SvgImageComp name={MENU_ICON}/>}
centerChild={
<TextComp text={'Title'} style={compStyle.title}/>
}
/>
<View style={{
flex: 1,
justifyContent: 'flex-end'
}}>
<KeyboardAvoidingView
behavior={"height"}
>
<TextInputComp fontFamily={NUNITO_SANS_REGULAR}
fontSize={15}
lineHeight={20}
autoFocus={true}
style={{
paddingVertical: 10,
paddingHorizontal: 20,
borderWidth: 1,
borderColor: '#000',
borderRadius: 200,
}}
/>
</KeyboardAvoidingView>
</View>
</>
For Android you don't need to pass behavior to KeyboardAvoidingView. For IOS you need to pass behavior="position" and keyboardVerticalOffset=[height of your input].
<KeyboardAvoidingView
{...(Platform.OS === 'ios'
? {
behavior: 'position' ,
keyboardVerticalOffset: [inputHeight], // calculate height using onLayout callback method
}
: {})}>
I avoid this issue by wrapping the screen in <ScrollView contentContainerStyle={flexGrow: 1}><ScrollView> This will make the whole screen turn into a scroll view once the keyboard opens. Allowing the box to be out of the way of the keyboard. This also has the added benefit of allowing you to scroll to other sections of the screen for reference while the keyboard stays open.

Material-UI Drawer rounding off corners leaves whitespace

I'm using the drawer from Material UI and I'm trying to round the corners using CSS like so:
style={{
borderRadius: "25px",
backgroundColor: "red",
overflow: "hidden",
padding: "300px"
}}
It works kinda, but the actual corners remain white instead of transparent.
How can I fix it such that the corners are properly rounded off? I've put my code in the following codesandbox:
https://codesandbox.io/s/material-demo-q3n14
Reason
Your SwipeableDrawer wraps your content inside a <Paper /> component. A Materiaul-UI paper component has shadows and a non-transparent background.
Solution
You do not use classnames, you use style, so the right way would be to set the SwipeableDrawer paperProps to:
PaperProps={{ elevation: 0, style: { backgroundColor: "transparent" } }}
Elevation: 0, so that there are no shadows anymore
backgroundColor: 'transparent', so that there is no background except yours
PS: Instead of having your borderRadius on your div, you may set it on the paper itself using the same prop
PaperProps={{ square: false }}
And remove your borderRadius from your div
Using classNames
If you used classNames (doc), you could have set the paper className to one of yours, using the classes prop:
classes={{ paper: classes.someClassName }}

How to render a View within a View without impacting styling

So I'm rendering a View that will display a number of components. Everything looks the way it should when I'm not using the nestedContainer. Each component is spaced out the way it should and it's aligned properly. Now if I add the View with the nestedContainer style, it no longer applies space-around to the HandRolledIcon and UserName component. How do I work around this and make sure those components within the nested View uses the styles I want?
(This question is related to my other question which contains more details)
<View style={styles.container}>
<View style={styles.nestedContainer>
<HandRolledIcon style={styles.hrIcon} />
<UserName style={styles.userName} />
</View>
</View>
container: {
flex: 1,
justifyContent: 'space-around',
flexDirection: 'column',
alignItems: 'center',
},
nestedContainer: {
alignItems: 'center',
justifyContent: 'space-around',
},
hrIcon: {
alignItems: 'center',
},
userName: {
alignItems: 'center',
}
I actually don't know what you're trying to achieve, But I feel u must brush up your flex-box knowledge.
Check out these links it might help you
https://tympanus.net/codrops/css_reference/flexbox/
https://facebook.github.io/yoga/docs/getting-started/
One way of achieving your result is giving flexGrow:1 (flex: 1 kind of works the same in react-native) to your nested container, which will make your nested container view to occupy all the extra space.
nestedContainer: {
flexGrow: 1,
alignItems: 'center', // <--- This can be removed based on your requirements since its already given to the parent view
justifyContent: 'space-around',
},
NOTE: This is just one way, other ways might be possible just go through the flex-box docs thoroughly.

React-Native - KeyboardAvoidingView - Error

I use the keyboardAvoidingView, to display inputs and used next focus. But, when i click in first input ( print label 1623 - Acidez ), this is hidden. How make show this?
<ReactNative.View key={this.state.selectedTabIndex}>
<ReactNative.ScrollView style={{ height: this.props.styles.height - 40 }}>
<ReactNative.KeyboardAvoidingView
keyboardVerticalOffset={0}
behavior="position"
contentContainerStyle={{ paddingTop: this.state.size }}
>
{this.tabs[this.state.selectedTabIndex].render()}
</ReactNative.KeyboardAvoidingView>
</ReactNative.ScrollView>
</ReactNative.View>
if you increase 'keyboardVerticalOffset' to bigger value like '100' of KeyboardAvoidingView to some bigger amount it would scroll up from keyboard thus avoiding it.I also spent much time in finding the right solution on internet but finally figure it out myself for 'react-native' version '0.50.4'.I got it working like this
<View style={…..}>
<ScrollView>
<KeyboardAvoidingView style={{ flex: 1 }}
keyboardVerticalOffset={100} behavior={"position"}>
</KeyboardAvoidingView>
</ScrollView>
</View>
keyboardVerticalOffset should be the distance between the top of the screen and the top of the KeyboardAvoidingView. If you're using flex, that number is going to be different depending on the size of the device you're viewing the app on.
The simplest approach I have found is to simply wrap the whole page with KeyboardAvoidingView. By making it your top-level wrapper, you will never have to worry about the keyboardVerticalOffset.
Experiment with the three behavior options from there until you get something that works.
What works today for me - on android - was..
<KeyboardAvoidingView
key={2}
keyboardVerticalOffset={0}
behavior={"padding"}
style={{
flex: 1,
overflow: "hidden",
height: "100%",
paddingTop: 0,
marginTop: 0,
borderTopWidth: 0,
}}
windowSize={1}
enabled
>
(...)
</KeyboardAvoidingView>

How to define width by percentage in react native?

I am trying to create a view with a border around it that is centered and fills 80% of the screen. I have come up with this:
<View style={{flexDirection: 'row'}}>
<View style={{flex: .1}} />
<View style={{flex: .8, borderWidth: 2}} />
<View style={{flex: .1}} />
</View>
which works, but seems awfully verbose.
Is there a better (more succinct) way to create a view that is a certain percentage of the screen width and centered in the page?
UPDATE:
Starting from React Native version 0.42 we now have a full percentage support for width, height , padding and so on, see the full list and examples here:
https://github.com/facebook/react-native/commit/3f49e743bea730907066677c7cbfbb1260677d11
Old method:
Consider using Dimensions, like:
import Dimensions from 'Dimensions';
and then in element's style:
width: Dimensions.get('window').width / 100 * 80,
Working example: https://rnplay.org/apps/4pdwlg

Categories

Resources