Create multiple curve points in react native component - reactjs

I am currently developing a react native app, and for my login screen it has a background that has two points where the component changes its curve. Attached is the image as it can better show what it looks like then I can explain it. I was wondering if it would be possible to recreate this screen in React Native. I have access to react-native-svg but I am using expo.
As you can see, there is two curves to the blue background/component part of the screen. (This is a mockup created in Figma, not yet implemented in an App) How would I go about designing this in react native?

To use SVGs you have to use react-native-svg. Expo has it built in, though you can install it in any react-native package. You can read more about react-native-svg here.
It is fairly straight forward to use the library. As you already have a path for the SVG you can just use the Path property to draw the path on the screen.
import * as React from 'react';
import { Text, View, StyleSheet, Dimensions, TextInput } from 'react-native';
import { Constants, Svg } from 'expo';
const WIDTH = Dimensions.get('screen').width;
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Svg height={300} width={WIDTH}>
<Svg.Path
d="M-17.5 378.5C31.5 32.5 302.5 463 375 89C447.5 -285 375 644 375 644H0C0 644 -66.5 724.5 -17.5 378.5Z" // put your path here
fill="blue"
stroke="blue"
/>
</Svg>
<View style={{backgroundColor: 'blue', flex: 1}}>
<View style={{width: WIDTH - 60, height: 60, backgroundColor:'white', borderRadius: 30, margin: 30, justifyContent: 'center', paddingLeft: 10}}>
<TextInput
placeholder='email'
/>
</View>
</View>
</View>
);
}
}
You can see it working in the following snack https://snack.expo.io/#andypandy/svg-example
This is what it looks like on an iPhone X

Umm I would do this few different way such a svg (react-native-svg) but why do that much hard work when this can be achievable just using an background image.
Use ImageBackground (https://facebook.github.io/react-native/docs/imagebackground) and fix this easily. Then add the logo and the login container as children.
Let me know if this works for you. :)
EDIT:
You might want to look at https://github.com/vault-development/react-native-svg-uri as well.

Related

does View in react native work same as Div in HTML?

I want to render multiple element with different styles but View and child View is not working as div working in html. please guide or share some resources to learn how multiple View work in a return.
import React from 'react'
import { Button, StyleSheet, Text, View,ScrollView } from 'react-native';
export default function Home() {
return (
<View>
<View style={styles.container}>
<Text >
Books are the best Mentors
</Text>
</View>
<View>
<Text style={{backgroundColor:'red'}} >
Books are the best Mentors
</Text>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
container2: {
flex: 1,
backgroundColor: '#fff',
position:'absolute',
bottom:0
},
});
TL;DR <div> is not the same as <View>
It looks like the possible issue here is that <div> have different default styling, and you should always remember about this. For example the default value for flexDirection in RN is column, not row like we have with <div>s.
Even though the official RN documentation about View tells us this:
View maps directly to the native view equivalent on whatever platform React Native is running on, whether that is a UIView, <div>, android.view, etc.
We should always keep in mind the specifics of the particular platform we work with.
I would also recommend you to check out this tutorial regarding Flex styling in React Native to get better experience working with it.

BottomTabNavigator coming on top instead of bottom in React Native expo mobile app

I am developing a mobile react native expo app. I am using BottomTabNavigator (NavigationContainer). As the name suggests it should appear at the bottom but it is incorrectly appearing on top.
I already have another image (logo.png) on the top of the screen and the navigationbar (or NavigationContainer) is also coming on top and overlapping above the image. Please help me resolve this issue. See my code below:
In the below code MyTabs is the Navigator created from createBottomTabNavigator(). This is incorrectly appearing on top of the screen.
import React from 'react';
import { Image, StyleSheet, Text, View, SafeAreaView, StatusBar, Platform } from 'react-native';
import logo from './assets/logo.png';
import { NavigationContainer } from '#react-navigation/native';
import MyTabs from './navigator/AppNavigator';
export default function App() {
return (
<SafeAreaView style={{ paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight: 0 }} >
<View>
<View style={styles.container}>
<Image source={logo} style={{ width: 100, height: 100 }} />
<Text style={{color: '#888', fontSize: 18, alignItems: 'center'}}>
To share a photo from your phone with a friend or anyone, just press the button below!
</Text>
</View>
<View >
<NavigationContainer >
<MyTabs /> // This is incorrectly coming on top of screen.
</NavigationContainer>
</View>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
// justifyContent: 'center',
},
});
The NavigationContainer should be the outermost component in App. This then wraps the Tab.Navigator component (in your case MyTabs), where you create tabs linked to each of your components. Inside your components, you are able to utilize SafeAreaView to then display the image at the top of the screen. Any type of Navigation scheme has to be made the top most component in the hierarchy in react native, wrapping the rest of your components. I've altered your code below:
import React from 'react';
import { Image,  StyleSheet, Text, View, SafeAreaView, StatusBar, Platform } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
export default function App() {
  const Tab = createBottomTabNavigator()
  return (
    <NavigationContainer >
      <Tab.Navigator>  
        <Tab.Screen name="Home" component={myComponent} />
      </Tab.Navigator>
    </NavigationContainer>
  );
}
const myComponent = () => {
  return (
    <SafeAreaView style={{ paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight: 0 }} >
      <View>
        <View style={styles.container}>
          <Image source={require('#expo/snack-static/react-native-logo.png')} style={{ width: 100, height: 100 }} />
          <Text style={{color: '#888', fontSize: 18, alignItems: 'center'}}>To share a photo from your phone with a friend or anyone, just press the button below!</Text>
        </View>
      </View>
    </SafeAreaView>
  )
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
     alignItems: 'center',
    // justifyContent: 'center',
  },
});

fontFamily unrecognized in react native ios app

I'm struggling to get my font, PressStart2P, loaded on. Its a font from google fonts. . . Have gone through the following steps, multiple times, to make sure I wasnt sloppy. By all indications, the font should be available in the react native app.
created the assets folder at the root of my project directory
create the fonts folder within the assets folder and place the font files inside... exactly as the PostScript name indicates, and have used both .otf and .ttf versions of the font.
in package.json, specified where the custom fonts are located:
"rnpm": {
"assets": [
"./assets/fonts/"
]
},
in my terminal, entered npx react-native link
added my fonts in App.js
For reference, here is the entire App.js file:
import React, { Component } from 'react';
import { Text, View , TouchableOpacity} from 'react-native';
export default class HelloWorldApp extends Component {
render() {
return (
<View style={{ backgroundColor:'#e9ffc945',flex: 1,
justifyContent: "center", alignItems: "center" }}>
<Text style={{fontSize:26, color: "#85321b45",
fontFamily: "PressStart2P"}}>Allah'u'Abha :)</Text>
<TouchableOpacity
style={{
backgroundColor:'#a4a6fc19',
padding: 95,
borderRadius: 19,
}}
>
<Text
style={{
color: "white",
fontSize: 20
}}
>
</Text>
</TouchableOpacity>
</View>
);
}
}
Additionally, I've checked in my copy bundle resources, in my project target in xcode... the file is there. Any ideas out there ?
I think you are using Font Family name which is not recognized with iOS. Instead of Font Family name, you should use PostScript Name of each font
Open Font Book ( Spotlight type FontBook )
Select your Font and view more information and it will look like this
You need to give PostScript name of the font as fontFamily . Otherwise android will work but iOS will give errors.
This is updated codebase of your App.js
import React, { Component } from 'react';
import { Text, View , TouchableOpacity} from 'react-native';
export default class HelloWorldApp extends Component {
render() {
return (
<View style={{ backgroundColor:'#e9ffc945',flex: 1,
justifyContent: "center", alignItems: "center" }}>
<Text style={{fontSize:26, color: "#85321b45",
fontFamily: "PressStart2P-Regular"}}>Allah'u'Abha :)</Text>
<TouchableOpacity
style={{
backgroundColor:'#a4a6fc19',
padding: 95,
borderRadius: 19,
}}
>
<Text
style={{
color: "white",
fontSize: 20
}}
>
</Text>
</TouchableOpacity>
</View>
);
}
}
After that link your assets again and clean project using xcode and rebuild.
Now you are ready to go...
Make sure you have link your assets and clean project before running
The recommended way is to create your own component, such as MyAppText. MyAppText would be a simple component that renders a Text component using your universal style and can pass through other props, etc.
https://facebook.github.io/react-native/docs/text.html#limited-style-inheritance

Getting an entire black screen when running react-native run-ios

When running the code an emulator for an IOS phone is produced. The application launches but produces an entire black screen. The only way to see the text is by changing the color of the text. My code is seen in the bottom.
import React from "react";
import { AppRegistry, Text } from "react-native";
const App = () => {
return <Text style={{ color: "red" }}>Some Text</Text>;
};
AppRegistry.registerComponent("albums", () => App);
From my understanding. The initial default should be a white background and the text should be in black. Hope someone can help me better understand what the issue might be. This is my first attempt with React Native although I do have some experience with React.
Thank you
You need to wrap text in a View like
<View style={{backgroundColor: 'white'}}>
<Text style={{ color: "red" }}>Some Text</Text>
</View>
As for the default style being black text on white background, that's the case if you use react-native-init or Expo to generate the project.

Android Warning: Native component for "RCTMap" does not exist

I created a react native project and I am trying to use a map for Android. I am using airbnb react-native-maps package, as suggested in the Facebook react native page.
I followed the instructions, added my google api key in the manifest. In iOS it works perfectly, however on Android it gives me a warning and it does not show me the map: "Warning: Native component for 'RCTMap' does not exist".
Here is my code:
import React, { Component } from 'react';
import { Text, View, TouchableHighlight, MapView } from 'react-native';
import Header from '../common/header';
import HomeStyleSheet from '../../style/home/homeStyleSheet';
export default class Results extends Component{
//...
render(){
return (
<View style={{ marginTop: 20 }}>
<Header headerText='RESULTS'>
</Header>
<MapView
style={{ height: 300, marginLeft: 0, marginRight: 0 }}
showsUserLocation={true}
region={{
latitude: 43.683470,
longitude: -79.318006,
latitudeDelta: 0.03,
longitudeDelta:0.03
}}/>
<View style={{ height: 5, backgroundColor: 'blue' }}/>
</View>
);
}
}
What am I doing wrong? Why am I getting the warning? I searched similar problems here but almost everyone said to use airbnb react-native-maps (and l did). Thanks everyone
I can close the question. Between all the changes I did to make it work,I didn't realize I was importing MapView from 'react-native' instead of 'react-native-maps'. Fixed it:
import MapView from 'react-native-maps';

Resources