Custom shape and gradient in React native - reactjs

I wanted to know is it possible to achieve this kind of shape and also gradient but I want to achieve gradient over the status bar. So pretty much the same like in the attachment.
For linear gradient I know how to do it, I've used https://docs.expo.io/versions/latest/sdk/linear-gradient/
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<LinearGradient
colors={['#4c669f', '#3b5998', '#192f6a']}>
<Text>
Custom shape
</Text>
</LinearGradient>
</View>
This is the result I want to achieve. https://dribbble.com/shots/5484044-Profile/attachments/1186437

You can make a custom component and manipulate the view to achieve a certain shape. Basic shapes are described here: https://codedaily.io/tutorials/22/The-Shapes-of-React-Native , but you will surely have to experiment more yourself to achieve your effect.

Related

React Native/Flexbox align Text bottom right inline with other Text

I'm trying to design a Message Bubble like this:
Source: Telegram iOS App
Where the Message itself is a <Text> component, and the timestamp <Text> is nested inside the Message's <Text>:
return (
<MessageBubble {...props}>
<Text style={fontStyle}>
{message.text}
<Text style={timestampStyle}>
{message.timestamp}
</Text>
</Text>
</MessageBubble>
);
The above code looks like this:
As you can see, the timestamp renders immediately at the end of the message content, but I want it to align at the bottom right.
I tried to set timestampStyle to alignSelf: 'flex-end', flex: 1, flexGrow: 1, etc but it didn't render at the bottom right.
Note: I don't want to use position: 'absolute' since that would like this:
Does anyone have an idea how I can achieve the style of the Telegram message bubble with React Native's Flexbox system?

How to obtain sharp edged view in react-native?

is it possible to obtain below view in react native either using canvas or View?
I'm quite sure it's achievable if you use
Grey layer - White background with grey foreground, with borderBottomLeftRadius
White Layer - borderBottomLeftRadius BorderTopRightRadius
another layer with borderTopRightRadius
Example for grey layer
<View style={{ backgroundColor: '#FFF', height: 20 }}>
<View style={{ backgroundColor: "grey", borderBottomLeftRadius: '20%'}}>
content
</View>
</View>
You just have to play around with the background colors, borderColor and borderradius etc. Though it may not look exactly the same as what you want. and may appear different on different devices

React native, image not scaling - resizeMode has no useful effect

I have code that looks like this:
<View style={styles.logoContainer}>
<View style={styles.logoTextContainer}>
<Text style={styles.logoText}>{siteName}</Text>
</View>
<View style={styles.logoImageContainer}>
<Image source={logo} style={styles.logo} resizeMode="contain" />
</View>
</View>
With the relevant styles looking like this:
logoContainer: {
flex: 4,
alignSelf: 'stretch',
alignItems: 'center',
justifyContent: 'space-evenly',
// borderWidth: 1,
// borderColor: 'blue',
},
logoImageContainer: {
flex: 3,
justifyContent: 'center',
// borderWidth: 1,
// borderColor: 'red',
},
logo: {
width: 250,
height: 250,
},
The issue is that the (square) image does not scale to fit inside the container (the commented out borders are so that I can make sure the containers are where I think they are, and the right size - they are).
I have seen various questions about this - some concern remote images, not the case here. Other suggestions:
Set resizeMode as a prop to the Image element.
Set resizeMode as a style.
Do either of the above with the width as 'undefined' in the style.
Do either of the above with the width as 'auto' in the style.
None have made any difference, the only thing that works is setting width and height specifically, as seen in the code above. This looks ok on the more recent (read: larger) iPhone sims, but causes the image to overlap with other stuff on the iPhone 5 sim.
To check if the resizeMode prop is having any effect, I set it to 'center' (with no width or height styles). This was a bit more promising, as the image is now only slightly wider than the screen. However, it is still much taller than the view, which contradicts the docs on resizeMode: center:
center: Center the image in the view along both dimensions. If the
image is larger than the view, scale it down uniformly so that it is
contained in the view.
Trying to add width=auto/undefined to resizeMode="center", causes the image not to display at all.
The logoImageContainer is a defined size (defined through flexbox), and I just want the image scaled and centred to fit in it.

How to make parent's width wrap its content in React Native?

I am new to React Native so this might be a silly question.
What I am trying to get is something like this :
Where I have a parent view with 2 children, Image and Text, aligned vertically to the left. What I want is the parent view to cover only the width of its children. But instead what I get is this :
The parent view stretches to the complete width of the mobile screen.
Here is my code :
render () (<View style={{backgroundColor: '#333333'}}>
<Image source={btnImageSource} />
<Text>Some label</Text>
</View>);
Something similar to Android's 'wrap-content' width value.
You will be able to do this using flex. I found this guide to be very helpful when working with flex.
A good starting point would be to create a parent View that is flexDirection: row, justifyContent: flex-start
render () (
<View style={{justifyContent: 'flex-start', flexDirection: 'row'}}>
<View style={{backgroundColor: '#333333'}}>
<Image source={btnImageSource} />
<Text>Some label</Text>
</View>
</View>
);

How react native Text and Image responsive? smaller text and image in small device, bigger text and image in large device

How react native Text and Image responsive?
I only know the Flexbox can make layout responsive but seems can not apply in text and image.
e.g.Make my text and image smaller in iphone 4s, bigger in iphone 6
Thanks.
You can use Flexbox in order to make your application responsive.
For example, say you wanted to display a line of text and an image on the same line:
class ResponsiveExample extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.text}>
Example of centered text
</Text>
<Image
resizeMode={"contain"}
style={styles.image}
source={{uri: "your image"}}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between"
},
text: {
marginLeft: 20,
flex: 1
},
image: {
marginRight: 20,
height: 400,
flex: 3,
}
});
Now the text and image will be displayed relative to the screen size. The usual hangup here is that flexDirection defaults to column, which will make things line up vertically. You can see what happens when we flip from portrait to landscape orientation:
As you can see, the text and image respond to the change in orientation.
For a better overview of Flexbox, I like to refer to the following guide:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/.
Just keep in mind that React Native defaults to a flex-direction of column, so if you want things laid out horizontally, you'll have to explicitly set it to row.
I think react-native-fit-image is useful for you.
React Native Fit Image enables you to draw responsive image component.
You can use this component as below.
<FitImage
source={{ uri: 'http://facebook.github.io/react/img/logo_og.png' }}
style={styles.fitImage}
/>
You are right to think about Flexbox, simply wrap your Text and Image inside View and make those View flexbox responsive.

Resources