how to create react native header as svg/ and manipulating the svg? - react-native

I'm trying to create my custom header component for a react native app,
import React from 'react'
import { StatusBar } from 'react-native'
import Svg, { Path } from 'react-native-svg'
export default function App () {
StatusBar.setHidden(true)
return (
<Svg
xmlns='http://www.w3.org/2000/svg'
xlink='http://www.w3.org/1999/xlink'
width='100%'
height='186.919'
viewBox='0 0 574.211 186.919'
>
<Path
id='Path_2524-2'
data-name='Path 2524'
class='cls-1'
d='M-815.085,1.627-985.466,25.151a739.285,739.285,0,0,1-202.451,0L-1358.3,1.627V-123.778h543.212Z'
transform='translate(1373.8 134.28)'
fill={'red'}
/>
</Svg>
)
}
I have attached my code, as well as the outcome photo.
I've tried changing the values of height and width in the svg component with no luck,I have also tried containing it in a view with absolute position, it's not getting the full width as well, can someone help me to accomplish what is in the second photo?

Related

Tailwind - how to set default text color in React Native

Im building a project in react native and tailwind. For every text component, I am passing "text-black".
<Text style={tailwind('text-black')}> Hi </Text>
Can I set the default color for text component to be black somewhere to overcome this problem ?
You'll want to create a custom component that wraps the Text component and applies the default style you want.
import React from 'react';
import { Text } from 'react-native';
const DefaultText = ({ style, children }) => (
<Text style={[tailwind('text-black'), style]}>{children}</Text>
);
export default DefaultText;
Now, whenever you want to use a Text component and have it automatically be styled with the default color, just use the DefaultText component instead.

React Native Hook problem [ useNavigation ]

I am writing applications with React Native. I am using typescript. I am using Hook and getting an error in the application. When I searched, Hook is valid as of React-Native version 0.59.0 but I'm having trouble.
How can I solve it?
Hook Issue App
http://prnt.sc/vvkotk
import { useNavigation } from "#react-navigation/native";
import React from "react";
import { Dimensions, Image, StyleSheet } from "react-native";
import { Box, Header, Text } from "../../components";
import { useTheme } from "../../components/Theme";
const Drawer = () => {
const navigation = useNavigation();
const theme = useTheme();
return (
<Box flex={1}>
<Box flex={0.2} backgroundColor="white">
<Box
position="absolute"
top={0}
left={0}
right={0}
bottom={0}
borderBottomRightRadius="xl"
backgroundColor="secondary"
>
It looks like it doesn't recognise your custom useTheme hook. Please make sure the filename starts with use so useTheme.tsx of useTheme.jsx. Check the filename of your Drawer component as well to be sure. It should contain .jsx or .tsx.

Is there any example of using StrictMode with React-Native?

As I know about it, This checks and gives warnings for React-Native code and its lifecycles.
I read about it from What is StrictMode in react?
How can I use it in react native ?
Here is a simple example to use StrictMode in React Native
StrictMode can be directly imported from React and can used like wrapping up View inside it.
import React, {Component, StrictMode} from 'react';
import {View} from 'react-native';
class Example extends Component {
render() {
return (
<StrictMode>
<View />
</StrictMode>
);
}
}
export default Example;

Using Button from React Native and Native Base

I am using Native base library in React Native.
In native base, there is component called Button and also there Component Button from 'react-native'.
If i want to use both Button components simultaneously, what should I do?
You can use alias
import { Button } from 'react-native'
import { Button as ButtonBase } from 'native-base';
and
<Button /> {# React Native Button #}
<ButtonBase /> {# Native Base Button #}
You can simply use use ALIAS by adding word as between the default name and the new name you want example:
import {View as V} form react-native;
and in your render() function you can call it like the
<V>...</V>
so for your question you can do this you can do this
import {Button as ButtonMain} from react-native;
import {Button as ButtonRB} from react-native;
and you can call them in your render() function like this:
<ButtonMain />
<ButtonRB />

How to get the correct screen width in react-native iOS?

react-native Dimensions.get("window").width return 375 for an iPhone 6s....
it seems far from correct.
`
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Dimensions
} from 'react-native';
class AwesomeProject extends Component {
render() {
return <Text style={{margin:50}}>Width: {Dimensions.get("window").width}</Text>;
}
}
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);`
375 is the number of points across for the iPhone 6. For most things, points will be fine. But if you need pixels, you can use the PixelRatio API provided by React Native.
For example, to get the distance across the iPhone in rendered pixels you could use Dimensions.get('window').width * PixelRatio.get(), which should return 750 for the iPhone 6.