Comments (6)
Hi, @davidnum
You may use the safeRender
prop so it won't render the shadow twice (so the fps drop won't be as big), but won't be available at the first render. If you know the components size beforehand, you may use the size
prop to have the shadow from first render, and also enter this size on the FlatList optimizations, linked above, along with other possible optimizations.
As the FlatList takes into account each components size and the shadow changes its size twice with the automatic sizing on first render (and exact on the second), certainly it has a significant impact on the fps.
Also, as this apparently an emulator, you are inevitably going to have a significantly poorer performance. On a real device it performs better, even with a large number of views. And when using the prod app version, it performs even better than the dev version.
I really appreciate your detailed feedback and any other info you may want to add, but I don't see any other thing I can do besides rewriting the lib to have a single SVG at least on the second render (not feasible on first render as I found out on all the time I tinkered on it), and I am really not willing to do it right now, specially as this is the only complain, so I am closing this as a Won't Fix. Any code change suggestion is welcome.
from react-native-shadow-2.
Hi, can you send here a image of your app screen?
from react-native-shadow-2.
Hi, can you send here a image of your app screen?
Sample code:
import React from 'react';
import {FlatList, Text} from 'react-native';
import {Shadow} from 'react-native-shadow-2';
const data = Array.from(Array(1000).keys());
const App = () => {
return (
<FlatList
contentContainerStyle={{paddingHorizontal: 16, paddingTop: 50}}
data={data}
keyExtractor={item => item.toString()}
renderItem={({item}) => (
<Shadow
distance={8}
offset={[2, 2]}
viewStyle={{
backgroundColor: 'white',
height: 200,
marginBottom: 16,
width: '100%',
padding: 16,
borderRadius: 16,
}}>
<Text style={{marginBottom: 16}}>Some item #{item}</Text>
<Shadow
viewStyle={{
width: '100%',
padding: 16,
borderRadius: 16,
backgroundColor: 'white',
}}
distance={2}
offset={[0, 0]}
paintInside>
<Text>Inner</Text>
</Shadow>
</Shadow>
)}
/>
);
};
export default App;
from react-native-shadow-2.
This actually seems to be doing pretty well. I was surprised and even shocked about the RAM usage, but as you are using a non virtualized list of 1000 items, it looks corresponding.
Here is the code of the lib: https://github.com/SrBrahma/react-native-shadow-2/blob/main/src/index.tsx
I don't see how I can remove any Views to reduce your count.
If you need a list of so many items like you have there in your test case, there are the FlatList and SectionList components, that works around the VirtualizedList component.
If you are having performance issues, try those list components above.
Actually, sorry. I was kinda distracted and busy and haven't noticed that you are already using the FlatList 🤦
Before the lib went smarter with the shadow on the first render, it used a single SVG component for all the sides and corners. Now, it has a SVG for each of those, and react-native-svg certainly wrap each of them with a View, as it accepts the style
prop. And, there are other 3 Views in Shadow for positioning etc. But, reverting it or having it as a possibility still doesn't seem necessary to me. Why have you brought this up? Were you having performance issues?
from react-native-shadow-2.
Also, you should take a look at this page: https://reactnative.dev/docs/optimizing-flatlist-configuration
from react-native-shadow-2.
~ This actually seems to be doing pretty well. I was surprised and even shocked about the RAM usage, but as you are using a non virtualized list of 1000 items, it looks corresponding. ~
~ Here is the code of the lib: https://github.com/SrBrahma/react-native-shadow-2/blob/main/src/index.tsx ~
~ I don't see how I can remove any Views to reduce your count. ~
~ If you need a list of so many items like you have there in your test case, there are the FlatList and SectionList components, that works around the VirtualizedList component. ~
~ If you are having performance issues, try those list components above. ~
Actually, sorry. I was kinda distracted and busy and haven't noticed that you are already using the FlatList 🤦
Before the lib went smarter with the shadow on the first render, it used a single SVG component for all the sides and corners. Now, it has a SVG for each of those, and react-native-svg certainly wrap each of them with a View, as it accepts the
style
prop. And, there are other 3 Views in Shadow for positioning etc. But, reverting it or having it as a possibility still doesn't seem necessary to me. Why have you brought this up? Were you having performance issues?
As you can see, list with Shadow dropping fps of UI and JS thread against list with simple View.
Code: https://github.com/davidnum/rn-shadow-2-issue
2021-11-17.12.33.33.mov
2021-11-17.12.33.56.mov
from react-native-shadow-2.
Related Issues (20)
- Not able to apply shadow on Pressable HOT 4
- Bug: The argument must be a React element, but you passed null with & weird behavior in corners - newest version HOT 17
- Support multiple children and follow shape of SVG HOT 1
- Have tried to use this lib, but I can't. What am doing wrong? HOT 5
- [Fixed in v13.6.0] Incompatible with react-native-svg v13.5.0 HOT 5
- On IOS, setting distance=0 does not work properly HOT 2
- Border radius problem HOT 2
- x-axis offset not working as expected (iOS) HOT 1
- could you provide a new prop `blur`? HOT 3
- X offset not working on IOS HOT 1
- Inner shadow HOT 4
- Issue with borderRadius in the latest version 7 when size of the elements changes HOT 5
- Unable to find an element with testID HOT 3
- Can I do this effect with this library? HOT 1
- Sides and corners HOT 2
- Fail to compile on web "Support for the experimental syntax 'jsx' isn't currently enabled" HOT 3
- Android
- SVGs in corners with border radius are not aligned properly HOT 9
- I'm using react-native-shadow-2 but it's weirdly slow when switching to screen ? HOT 2
- the shadow can not as same as web css HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-shadow-2.