I have two flatlist, one contains the data (dataScroll) and the other the checkboxes (checkScroll) for every data item.
The reason for this is that the checkboxes have to be always visible while the user scrolls horizontaly on the dataScroll (I put the dataScroll in a horizontally scrollable scrollview).
Demo:
expo snack demo
Tried so far:
On dataScroll's scroll event, I got the y offset and moved the checkScroll to that y position.
handleDataScroll = ({ nativeEvent: { contentOffset: { y } } }) => {
this.checkScroll.scrollToOffset({ offset: y, animated: true });
}
It (almost) does the job, but there is a huge delay between the 2 flatlist while scrolling.
--
I read that maybe the use of animated components the way to go, but I couldn't figure out how the animation works in react native.
So I'd like to get some help on how should I bind the two flatlist together so that if I scroll on one list, the other follows it with no (or at least minimal) delay.
If only the dataScroll flatlist is scrollable that's ok too.
Related
I have a small app where I am testing the animations for the items. Basically when I swipe the item, it gets removed from the list and the animation is continued for like 0.5s. The problem is that the mobx updates the array when the item is removed from it and it cancels out the animation. So instead of animation continuing to show removal or addon effect, it just disappears quickly.
How do I avoid this? I can have timeouts to wait for the animation to finish and remove an item, but more importantly, the issue is the same if I fetch the data and the array is topped up, I get the same animation cancelling effect.
To show how I am rendering the components would be something like this:
private renderCards = () => {
const {fakeData} = this.props.mainStore
const el = []
fakeData.forEach(fd => {
el.push(
<Draggable key={fd.id}>
<ItemCard item={fd} />
</Draggable>,
)
})
return el
}
Example to replicate is here https://snack.expo.dev/Jh0Vk0cTX
Why Vuejs scrolls to top of the page after re-rendering a component . It makes it feel like refreshing the page. How may I prevent this scrolling and having the page fixed in it's position
Imaging after clicking on some part it is going to re-render it's component
Here is the piece of code where I do the update , then scrolling to top happens
methods: {
updateData(data) {
let updatedCategory = data.category;
updatedCategory = new Category(updatedCategory);
updatedCategory.isDefault = 1;
for (let cat in this.categories){
if(this.categories[cat].id === updatedCategory.id){
Vue.set(this.categories,cat, updatedCategory);
}
}
}
},
Discover what element has the scroll bar.
Before updating your data, capture the ele.scrollTop.
Update your data.
In a nextTick, restore the element's scrollTop.
https://www.w3schools.com/jsref/prop_element_scrolltop.asp
Stuck with small problem. I have Animated.ScrollView and there i have onScroll Event like this
Animated.event(
[
{
nativeEvent: {
contentOffset: {
x: this.topViewAnimation,
},
},
},
],
{ useNativeDriver: true },
)
So onScroll that card which active ( on the screen ) highlights item in view.
Sometimes i need to scroll to specific value with scrollTo method but i always see one problem.
For example i have 10 items. ( 10 items in view and 10 items which i will highlight based on scrollOffset ).
When i will use my scrollTo method i will see how every item highlights untill it become this one what i need.
Is there a way to highlight only one item what i need?
I've just jumped into the same problem today, and after hours trying to solve this issue, the solution was quite straightforward.....
What I did is to NOT TO USE the Animated.ScrollView component, and instead, I created a new ScrollView animated component whith the animated interface:
const AnimatedScrollView = Animated.createAnimatedComponent(ScrollView)
Then I used this new "AnimatedScrollView" component insted of the "Animated.ScrollView" and everything run just smoothly...
Good luck!
We were asked to implement a screen for our app where there would be some data in the form of a list and sections for each data category. When a Section header is pressed, the section data should be expanded or collapsed.
At first, i tried with Listview, and i was changing the datasource each time a header was pressed, but tbh it did not feel like the correct way of doing it.
Creating a custom view, an animating the view's height works ok, but because of the volume of the data, which is big, the initial rendering is a bit slow e.g. there is a noticeable delay when navigating to the screen.
After upgrading to RN 44.3 i was wondering if i could use Sectionlist in a better way than listview.
Generally what's the best way of approaching a requirement like this?
Thanks!
You can animate the items in flatlist/SectionList. A smaple code will look like below (Animates on removing items). You can use same logic for section list as well.
onRemove = () => {
const { onRemove } = this.props;
if (onRemove) {
Animated.timing(this._animated, {
toValue: 0,
duration: ANIMATION_DURATION,
}).start(() => onRemove());
}
};
Refer this link for more details.
I'm using onLayout to detect screen orientation and it's working fine inside my root view, but when I implemented inside the drawer it didn't work, any reason why this happens ?
code :
import Drawer from 'react-native-drawer'
...
onLayout(e) {
console.log('onLayout');
}
<Drawer onLayout={this.onLayout}
It didn't log any thing when orientation changed!
This is because the Drawer component doesn't take onLayout as a prop. You can see in the source code that the rendered View does use onLayout, but it's not pulling from something like this.props.onLayout.
I'm not exactly sure what you're looking to do, but maybe this issue will help you. As it shows, you can pass a function into openDrawerOffset instead of an integer or a ratio in order to be a little more dynamic with how you set your offset:
openDrawerOffset={(viewport) => {
if (viewport.width < 400) {
return viewport.width * 0.1;
}
return viewport.width - 400;
}}
You might also benefit from the Event handlers that react-native-drawer has to offer.