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

TypeError: null is not an object (evaluating 'cards[index]') #88

Open
privatepej opened this issue Oct 23, 2022 · 5 comments
Open

TypeError: null is not an object (evaluating 'cards[index]') #88

privatepej opened this issue Oct 23, 2022 · 5 comments

Comments

@privatepej
Copy link

TypeError: null is not an object (evaluating 'cards[index]')
Warning: Failed %s type: %s%s, prop, The prop cards is marked as required in Swiper, but its value is null.,

@privatepej
Copy link
Author

image

@thinktapper
Copy link

I keep getting TypeError: undefined is not an object (evaluating 'value.getValue')

Could these be related?

@nofacez
Copy link

nofacez commented Nov 29, 2022

Could you please provide a more detailed description of the issue? Especially when does it occur? I might know how to fix a similar bug but I don't know if it is the same one

@thinktapper
Copy link

thinktapper commented Jan 10, 2023

shoot, how did not see this reply til now 🙈 my b @nofacez
I must've fixed my particular issue back then somewhere

@mikpalm
Copy link

mikpalm commented Dec 12, 2024

Just solved the above error with getValue issue..
made a patch-package react-native-deck-swiper+2.0.17.patch

diff --git a/node_modules/react-native-deck-swiper/Swiper.js b/node_modules/react-native-deck-swiper/Swiper.js
index ba9fafe..15dff26 100644
--- a/node_modules/react-native-deck-swiper/Swiper.js
+++ b/node_modules/react-native-deck-swiper/Swiper.js
@@ -57,8 +57,16 @@ class Swiper extends Component {
    this._animatedValueX = 0
    this._animatedValueY = 0

-    this.state.pan.x.addListener(value => (this._animatedValueX = value.value))
-    this.state.pan.y.addListener(value => (this._animatedValueY = value.value))
+    this.state.pan.x.addListener(value => {
+      if(value && value?.value !== undefined){
+        this._animatedValueX = value.value
+      }
+    })
+    this.state.pan.y.addListener(value => {
+      if(value && value?.value !== undefined){
+        this._animatedValueY = value.value
+      }
+    })

    this.initializeCardStyle()
    this.initializePanResponder()
@@ -646,7 +654,7 @@ class Swiper extends Component {
    this.getCardStyle(),
    {
      zIndex: position * -1,
-      transform: [{ scale: this.state[`stackScale${position}`] }, { translateY: this.state[`stackPosition${position}`] }]
+      transform: [{ scale: this.state[`stackScale${position}`] !== undefined ?this.state[`stackScale${position}`] : 1 }, { translateY: this.state[`stackPosition${position}`] !== undefined ? this.state[`stackPosition${position}`]:0 }]
    },
    this.props.cardStyle
  ]
@@ -761,22 +769,27 @@ class Swiper extends Component {
    return cardIndex
  }

-  pushCardToStack = (renderedCards, index, position, key, firstCard) => {
+  pushCardToStack = (index, position, key, firstCard) => {
    const { cards } = this.props
    const stackCardZoomStyle = this.calculateStackCardZoomStyle(position)
    const stackCard = this.props.renderCard(cards[index], index)
    const swipableCardStyle = this.calculateSwipableCardStyle()
    const renderOverlayLabel = this.renderOverlayLabel()
-    renderedCards.push(
+    
+    return (
      <Animated.View
        key={key}
        style={firstCard ? swipableCardStyle : stackCardZoomStyle}
        {...this._panResponder.panHandlers}
-      >
-        {firstCard ? renderOverlayLabel : null}
-        {stackCard}
+       >
+         {firstCard ? renderOverlayLabel : null}
+         {stackCard}
      </Animated.View>
    )
+    
+    
+    
+   
  }

  renderStack = () => {
@@ -790,9 +803,10 @@ class Swiper extends Component {
    
    while (stackSize-- > 0 && (firstCard || showSecondCard) && !swipedAllCards) {
      const key = this.getCardKey(cards[index], index)
-      this.pushCardToStack(renderedCards, index, cardPosition, key, firstCard)
    
-      firstCard = false
+       renderedCards.push(this.pushCardToStack(index, cardPosition, key, firstCard))
+
+       firstCard = false

      if (index === cards.length - 1) {
        if (!infinite) break
@@ -802,6 +816,7 @@ class Swiper extends Component {
      }
      cardPosition++
    }
+    
    return renderedCards
  }

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

4 participants