Comments (11)
Why not simply use a key change as a workaround?, i agree it is unacceptable that it does not change when the props change, but in the mind-time the key change works:
const Component = ({ children }) => {
const keyValue = useMemo(() => someKeyGenerator(), [children])
return (
<Swiper key={keyValue}>{children}</Swiper>
)
}
It's not pretty but works
from react-native-web-swiper.
What??? This is not good behavior. Why in the world Swiper
does not rerender???
from react-native-web-swiper.
Thanks @Jorge-Luis-Rangel-Peralta this is working as great.
I add uuidv4 into key and it's working well.
from react-native-web-swiper.
@YevheniiShabelnykkk How to reproduce it? Please make a snack with issue
from react-native-web-swiper.
Hm, I am afraid I can't do it snack; But I can write code here:
Main screen, where I import Carousel;
import React from 'react';
import { View, Text, Image } from 'react-native';
import { connect } from 'react-redux';
import ViewWrapper from '../../../shared/ViewWrapper';
import Button from '../../../components/onboarding/Button';
import FooterButton from '../../../components/claims/FooterButton';import { openIntercom } from '../../../helpers/openIntercom';
import Carousel from '../../../components/claims/Carousel';
import styles from './styles';
class ClaimsScreen extends React.Component {
_onLetsDoThisButtonPress = () => {
this.props.navigation.navigate('ClaimsList');
};_onGetHelpButtonPress = () => {
openIntercom();
};render() {
const { claims } = this.props;console.info('claims', claims); const isDisabledButton = !Boolean(this.props.policies.length); return ( <ViewWrapper padding style={styles.viewWrapper} contentContainerStyle={styles.contentContainerStyle} > <View style={styles.container}> {claims && claims.length ? ( <Carousel claims={claims} /> ) : ( <React.Fragment> <Text style={styles.title}>Claims</Text> <Text style={styles.subTitle}>Submit your claim</Text> <View style={styles.timeWrapper}> <Image source={require('../../../assets/icons/watch-icon-white.png')} /> <Text style={styles.timeText}>Around 9 minutes</Text> </View> <Button title="Let's do this!" onPress={this._onLetsDoThisButtonPress} isDisabled={isDisabledButton} /> </React.Fragment> )} </View> {claims && claims.length && ( <FooterButton title="Start a new claim" subTitle="Submit a claim in less than 10 mins" onPress={this._onLetsDoThisButtonPress} /> )} <FooterButton title="Get some help" subTitle="Not sure if you should make a claim? Have another question?" onPress={this._onGetHelpButtonPress} /> </ViewWrapper> );
}
}const mapStateToProps = state => ({
policies: state.user.policies,
claims: state.claims
});export default connect(mapStateToProps)(ClaimsScreen);
`
And screen with Carousel:
import React from 'react';
import { View } from 'react-native';
import Slide from '../Slide';
import Swiper from 'react-native-web-swiper';
import styles from './styles';
const Carousel = ({ claims }) => {
return (
<Swiper
controlsProps={{
prevTitle: null,
nextTitle: null,
dotActiveStyle: styles.dotActiveStyle
}}
controlsEnabled={claims.length > 1}
slideWrapperStyle={styles.slideWrapperStyle}
>
{claims.map((claim, index) => {
return (
<Slide
key={${claim.category}${index}
}
category={claim.category}
status={claim.status}
dateSubmitted={claim.created}
reference={claim.reference}
/>
);
})}
);
};export default Carousel;
You can see, I work with redux, and when claim.length
is changed, I want to rerender Carousel component.
from react-native-web-swiper.
I saw in Swiper file in library, you have only constructor
so it renders only one time and then not rerender;
Maybe, you need to add ComponentDidUpdate
method?
from react-native-web-swiper.
@YevheniiShabelnykkk I will try to look into this. You can check this for now. I think it helps
from react-native-web-swiper.
No, its not help, you wrote about rerender slide, but I need to add new slide in Swiper;
For example, I have 3 slides and after some changes I click button and want to see new slide 4 in Swiper
Thanks!
from react-native-web-swiper.
This is really needed for us
from react-native-web-swiper.
@Jorge-Luis-Rangel-Peralta what about if I want to get the isSwiping
state using onAnimationStart
and onAnimationEnd
, and update the content of the view ? I keep having no rerender of the cards as I am not editing children
which is passed upper in the JSX tree. Did anyone found a workaround for this?
I have tried to get the switching state but forcing the whole rerendering break it all and it's not swipeable:
const keyValue = useMemo(() => Math.random(), [props.cards, swiping])
from react-native-web-swiper.
Why not simply use a key change as a workaround?, i agree it is unacceptable that it does not change when the props change, but in the mind-time the key change works:
const Component = ({ children }) => { const keyValue = useMemo(() => someKeyGenerator(), [children]) return ( <Swiper key={keyValue}>{children}</Swiper> ) }
It's not pretty but works
Why not simply use a key change as a workaround?, i agree it is unacceptable that it does not change when the props change, but in the mind-time the key change works:
const Component = ({ children }) => { const keyValue = useMemo(() => someKeyGenerator(), [children]) return ( <Swiper key={keyValue}>{children}</Swiper> ) }
It's not pretty but works
This works perfectly for me!! thanks a lot @Jorge-Luis-Rangel-Peralta
from react-native-web-swiper.
Related Issues (20)
- Expo Video Component (expo-av) Doesn't fully render in Swiper
- Swiper slider only show when I set hieght for parent view of this.
- Animations
- Even if image state is removed, it is visible in the swiper.
- swiper arrows web
- in iOS ScrollView inside swiper conflict scroll! HOT 7
- Multiple elements HOT 3
- gesturesEnabled problem disable swiper HOT 1
- [Help needed] Rerender different sets of children HOT 1
- Safari Mobile iOS 12, width and height are always equal to 0 HOT 1
- Bouces disable? HOT 7
- Possible to add slides dynamically? HOT 6
- Not displaying in React Native Web HOT 2
- Allow `React.Component`s to be functional components (TypeScript) HOT 4
- Swiper Doesnt Render Anything HOT 4
- Warning: Failed prop type: DefaultControls: prop type `cellsStyle.top-left`
- Fade transition HOT 2
- Issue and Fix: Components not getting prop updates HOT 1
- swipe is not working in android HOT 1
- Disable spring animation.
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-web-swiper.