GithubHelp home page GithubHelp logo

Comments (11)

Jorge-Luis-Rangel-Peralta avatar Jorge-Luis-Rangel-Peralta commented on June 8, 2024 16

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.

sakhmedbayev avatar sakhmedbayev commented on June 8, 2024 3

What??? This is not good behavior. Why in the world Swiper does not rerender???

from react-native-web-swiper.

Shing-Ho avatar Shing-Ho commented on June 8, 2024 2

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.

oxyii avatar oxyii commented on June 8, 2024

@YevheniiShabelnykkk How to reproduce it? Please make a snack with issue

from react-native-web-swiper.

YevheniiShabelnykkk avatar YevheniiShabelnykkk commented on June 8, 2024

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.

YevheniiShabelnykkk avatar YevheniiShabelnykkk commented on June 8, 2024

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.

oxyii avatar oxyii commented on June 8, 2024

@YevheniiShabelnykkk I will try to look into this. You can check this for now. I think it helps

from react-native-web-swiper.

YevheniiShabelnykkk avatar YevheniiShabelnykkk commented on June 8, 2024

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.

dhirajanand014 avatar dhirajanand014 commented on June 8, 2024

This is really needed for us

from react-native-web-swiper.

kopax avatar kopax commented on June 8, 2024

@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.

jorgezerpa avatar jorgezerpa commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.