How to have linear gradient background on all screens in React Native - reactjs

I have an app written in React Native. I would like to have a gradient background in all screens. Maybe something like:
I have found the react-native-linear-gradient package, but would I get higher performance using an image?
Also, how do I make sure it stays as a background on all pages?
Would it be something like
const Container = (props) => (
<View>
<LinearGradient colors=['blue', 'orange', 'blue'] />
{props.children}
</View>
);
and then on all my screens use
<Container>
..
</Container>

You can try to create gradient image in some graphical editors which allow you to set linear gradient from top(blue) to bottom(transparent), and place this image as background all your scenes. Its can be helpful.
But if you need to cange colors of your gradient dynamically, you need to use libraries for now.

Related

React Native: circle pulse loop animation with Animated

I want to have a looped pulse effect on my circle View similar to this in my react-native app using only Animated api, no react-native-animated since I get build error with it.
https://codepen.io/Yario/pen/bQZMBM?css-preprocessor=scss
I only want the outer effect, no shrinking.
I think this could be done with scale and maybe opacity for added better effect but all the examples I found use reanimated and I don't have the knowledge to reverse engineer the examples.
<Animated.View style={{ animatedStyle, width:50, height:50, borderRadius:50/2, backgroundColor:'red' }} />
Can someone with more expertise on Animated api help me?

React Native Notification Tray and AppBar color

I am using react-native-paper along with react-navigation and the notification tray background color is not a darker shade of the AppBar color as shown in the documentations of react-native-paper and I cannot figure a way out to do that.
I have a basic project implemented and the snack of it can be seen in the following link:
https://snack.expo.dev/#throwawayacc/grumpy-milkshake
Expected Output:
Current Output
As it can be seen above the notification tray color is the same as the AppBar color. How do I get it to work like the expected output. You can see the current implementation on the link above.
You can use this https://reactnative.dev/docs/statusbar#backgroundcolor-android to change the status bar to a different color.
Just import the StatusBar from react-native. And put this code in your screens components like this. e.g.
// codes...
function HomeScreen(props) {
return (
<View style={style.container}>
<StatusBar
animated={true}
backgroundColor="#3B008F"
/>
<Text>Home Screen</Text>
// codes...

Can you display a popup modal inside a react-three-fiber canvas?

I am trying to extend this react-three-fiber Game Demo. I want to show a popup modal when the player interacts with a computer. I want to render different React components inside the modal that are styled using TailwindCSS.
Do you know if this is something you can do with react-three-fiber? Any help would be appreciated!
As far as I know, you can't render DOM-elements directly with three.js.
As a workaround, you can create images of your react components for example with html2canvas. Then you use these images as textures for a 2D plane.
Yes it is possible,
If you want to render the element as a game element you can look at sprites or the drei billboards.
drei billboard
If you want to render it as html it's even easier, just put your dom elements outside of the react three fiber canvas element.
like so :
<div>
{showElementState&&<div><input type="range" ref={someRef}/></div>}
<Canvas>
<mesh onClick={()=>setShowElementState(true)} >
<boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color={'orange'} />
</mesh>
</Canvas>
</div>
or you could also just use the leva package(which is recommended on the react-three-fiber github):
https://github.com/pmndrs/leva
This is a simple enough solve, while three.js doesn't render DOM elements it can still be used to manipulate elements already in the DOM. So if you want to change the display of an elements, or have it translate and follow a 3D object this is easy enough with vanilla three.
Lucky for you you have access to all the perks of three-fiber so I would say just use the Drei Html component. I'll just leave the storybook here, it should go over any questions you have for it
Html Storybook Drei

How to properly implement the statusbar in the components using React Native

I have task where I need to change the statusbar from white and make the content dark. Now I search how the statusbar implement to the component. Yes it works properly. Later on I experience bugs where If I re render the entire application I mean when I re open the application again. the status bar that I change it turns to the original color which is blue. so to make more details I will show you the code that I implement and the screenshot of my application that I created.
Here is some research that I read:
Reference
I don't think there is any conflict between react-navigation and the StatusBar, but I think you should use the component rather than the imperative API. There's a high chance this is due to a re-render of your app and it just switch back to the default, with a component declare, you ensure it won't happen.
Goal: To make the statusbar won't change to blue if I re open the application again.
Here is what I implement on my application:
React Navigation 5 (For Navigation)
Native Base
Statusbar:
<StatusBar hidden={false} animated barStyle="dark-content" backgroundColor="#FFFF" />
Bug Status Bar:
Goal Status Bar:
Code Works might only for the android device as we have to manage the safeAreaView in iOS device
Check out the below code example to show the custom status bar color.
<View style={{ flex: 1 }} >
<StatusBar animated backgroundColor="pink" barStyle="dark-content" />
<View style={{ flex: 1, backgroundColor: "green" }} >
</View>
</View>
Might you will be able to see the status bar color pink and dark content into it and whole screen with green color.

How do you distinguish between FontAwesome's circles?

I am rendering an icon in my React Native app, and have to specify the checked/unchecked icon type. I am reading the list of FontAwesome icons here: https://fontawesome.com/icons?d=gallery&q=circle
There are many different circle icons called "circle". When I specify "circle" as the icon type in my app, it uses the filled circle by default, but I want to use the outline circle. Does anyone know how to do this? Specifically, I am rendering a <CheckBox> component and specifying the uncheckedType field.
I’d recommend using react-native-vector-icons which includes FontAwesome. Check out the directory of all the icon packs here.
That all have unique names, so the code would look something like this:
import Icon from 'react-native-vector-icons/FontAwesome';
const checked = <Icon name="circle" size={30} color="#900" />;
const unchecked = <Icon name=“circle-o” size={30} color={#900} />;
This will make it really easy to quickly add all kinds of icons into your app!

Resources