Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug swipe animation when adding new cards after renderNoMoreCards #135

Open
dengue8830 opened this issue Dec 10, 2018 · 3 comments
Open

Comments

@dengue8830
Copy link

dengue8830 commented Dec 10, 2018

first load cards

image

adding cards after renderNoMoreCards shows this when swipping first card (second and later swipes fine)

image

my code

async onNuevaSolicitud(solicitudDeViajeId: string) {
    const res = await http.get<{ solicitud: ISolicitudDeViajeAttrs }>(`${APIs.CHOFER_BUSCA_NUEVA_SOLICITUD}/${solicitudDeViajeId}`);
    this.setState({
      solicitudes: this.state.solicitudes.concat(SolicitudDeViaje.parseItem(res.data.solicitud))
    });
  }

  onCardRemoved(index: number) {
    this.setState({
      solicitudes: this.state.solicitudes.slice(1, this.state.solicitudes.length)
    });
  }

...

<SwipeCards
                    cards={this.state.solicitudes}
                    renderCard={
                      (item: SolicitudDeViaje) =>
                        <TarjetaSolicitudViajeErrorBoundary key={item.id}>
                          <TarjetaSolicitudViaje
                            perfilUrl={item.viaje!.pasajero!.fotoPerfilUrl}
                            nombre={item.viaje!.pasajero!.nombre!}
                            tiempoPasado={item.createdAt!.fromNow()}
                            // distanciaAlPasajero={'3km'}
                            calleOrigen={item.viaje!.origen!.calle!}
                          />
                        </TarjetaSolicitudViajeErrorBoundary>
                    }
                    renderNoMoreCards={() => <CartelVacio texto='xSin solicitudes por el momento, espera un momento a que lleguen' />}
                    handleYup={this.onAceptarSolicitud}
                    cardRemoved={this.onCardRemoved}
                    onClickHandler={() => { }} // Evitamos el alert de la lib -.-
                    yupView={
                      <Row style={{ paddingLeft: 10, flex: 1, alignContent: 'center', justifyContent: 'center' }}>
                        <Text textStyle={{ alignSelf: 'center', color: '#7764CA' }}>Aceptar</Text>
                        <Icon iconStyle={{ alignSelf: 'center', paddingLeft: 5 }} color='#7764CA' name='ios-return-right-outline' />
                      </Row>
                    }
                    noView={
                      <Row style={{ paddingLeft: 10, flex: 1, alignContent: 'center', justifyContent: 'center' }}>
                        <Icon iconStyle={{ alignSelf: 'center' }} color='#757575' name='ios-return-left-outline' />
                        <Text textStyle={{ alignSelf: 'center', paddingLeft: 5, color: '#757575' }}>Rechazar</Text>
                      </Row>
                    }
                    loop={false}
                    nopeStyle={{ borderWidth: 0 }}
                    yupStyle={{ borderColor: '#7764CA' }}
                    // para stack: you need to set the stackOffsetX and you will be good try out stackOffsetX={2}
                  />
@dengue8830
Copy link
Author

temporally fixed forcing a unmount/mount with a second state

this.setState({estadoCarga: EstadoCarga.Cargando});
      this.setState({
        estadoCarga: EstadoCarga.Ocioso,
        solicitudes: this.state.solicitudes.concat(SolicitudDeViaje.parseItem(res.data.solicitud))
      });

...

{
            this.state.estadoCarga === EstadoCarga.Cargando &&
            <CartelCargando />
          }
          {
            this.state.estadoCarga === EstadoCarga.Ocioso &&
            <Swiper ... />
          }
}

@dengue8830
Copy link
Author

dengue8830 commented Dec 10, 2018

better solution: reset the buggy state

if (!this.state.solicitudes.length) { // wrap it in a if to avoid the unnecessary animation if it still have cards 
 this.swiper && this.swiper._resetState();
}
this.setState({
  solicitudes: this.state.solicitudes.concat(SolicitudDeViaje.parseItem(res.data.solicitud))
});

...

<SwipeCards
 ref={ref => this.swiper = ref!}
 ...
/>

@sleroy
Copy link

sleroy commented Oct 17, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants