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

Check value callback whether it is valid or not #5784

Merged
merged 4 commits into from
Mar 14, 2024

Conversation

vietdung97
Copy link
Contributor

TypeError: right operand of 'in' is not an object

image

TypeError: Cannot convert undefined value to object

image

Summary

Test plan

TypeError: right operand of 'in' is not an object
TypeError: Cannot convert undefined value to object
@tomekzaw
Copy link
Member

Hey @vietdung97, thanks for submitting this PR!

Just out of curiosity, could you please also share the code snippet that causes this error? We'd like to know how this error can be triggered from the user code.

@NikitaDudin
Copy link
Contributor

@tomekzaw this error appears on passing array with falsy condition or null or undefined element.

import { StyleSheet } from 'react-native';
import Animated from 'react-native-reanimated';

const styles = StyleSheet.create({
  style1: {
    flex: 1,
  },
  style2: {
    backgroundColor: '#ff0000',
  },
});

function Sample(): JSX.Element {
  // case 1
  const condition = false;

  return (
    <Animated.View style={[styles.style1, condition && styles.style2]} />
  );

  // case 2
  return (
    <Animated.View style={[styles.style1, null]} />
  );

  // case 3
  return (
    <Animated.View style={[styles.style1, undefined]} />
  );
}

export default Sample;

@tomekzaw
Copy link
Member

@NikitaDudin Thanks!

@vietdung97
Copy link
Contributor Author

vietdung97 commented Mar 13, 2024

Hey @vietdung97, thanks for submitting this PR!

Just out of curiosity, could you please also share the code snippet that causes this error? We'd like to know how this error can be triggered from the user code.

Here is my sample code. It appear due to animation entering={FadeIn}>. I try to removing this props then my project works normally

import React from 'react';
import { TextStyle, ViewStyle } from 'react-native';
import Animated, { FadeIn } from 'react-native-reanimated';
import { scale } from 'react-native-size-scaling';
interface ErrorLabelProps {
  text: string;
  containerStyle?: ViewStyle;
  textStyle?: TextStyle;
}
const ErrorLabel = ({ text, containerStyle, textStyle }: ErrorLabelProps) => {
  return (
    <Animated.View style={[{ paddingTop: scale(6) }, containerStyle]} entering={FadeIn}>
      ...
    </Animated.View>
  );
};

I don't have problems with style contains falsy conditions or null or undefined elements, @NikitaDudin

const ErrorLabel = ({ text, containerStyle, textStyle }: ErrorLabelProps) => {
  return (
    <Animated.View style={[{ paddingTop: scale(6) }, undefined, null]}>
      ...
    </Animated.View>
  );
};

@kesha-antonov
Copy link

I got this error with latest version of rnr

@NikitaDudin
Copy link
Contributor

@vietdung97 you right, this error appears for styles array with falsy(null, undefined, false) element when set entering animation

import { StyleSheet } from 'react-native';
import Animated, { FadeIn /* or other entering animation */ } from 'react-native-reanimated';

const styles = StyleSheet.create({
  style1: {
    flex: 1,
  },
  style2: {
    backgroundColor: '#ff0000',
  },
});

function Sample(): JSX.Element {
  // case 1
  const condition = false;

  return (
    <Animated.View entering={FadeIn} style={[styles.style1, condition && styles.style2]} />
  );

  // case 2
  return (
    <Animated.View entering={FadeIn} style={[styles.style1, null]} />
  );

  // case 3
  return (
    <Animated.View entering={FadeIn} style={[styles.style1, undefined]} />
  );
}

export default Sample;

cc @tomekzaw

@m-bert
Copy link
Contributor

m-bert commented Mar 14, 2024

Hi @vietdung97! Thanks for this PR! I've looked at it with @piaskowyk and we decided that it will be better to use filter.

If you could add

  componentStyleFlat = componentStyleFlat.filter(Boolean);

after componentStyleFlat declaration, we will be happy to merge this change!

@vietdung97
Copy link
Contributor Author

Hi @vietdung97! Thanks for this PR! I've looked at it with @piaskowyk and we decided that it will be better to use filter.

If you could add

  componentStyleFlat = componentStyleFlat.filter(Boolean);

after componentStyleFlat declaration, we will be happy to merge this change!

Hi @m-bert , I've made changes to my PR based on your comments. I believe it now addresses the feedback and would be happy if it's accepted.

Copy link
Contributor

@m-bert m-bert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing that ❤️

@m-bert m-bert added this pull request to the merge queue Mar 14, 2024
Merged via the queue into software-mansion:main with commit 9d81019 Mar 14, 2024
7 checks passed
bartlomiejbloniarz pushed a commit that referenced this pull request Mar 15, 2024
TypeError: right operand of 'in' is not an object


![image](https://github.com/software-mansion/react-native-reanimated/assets/50390141/a37e35de-e8a0-49b5-ba04-75cea807be19)

TypeError: Cannot convert undefined value to object


![image](https://github.com/software-mansion/react-native-reanimated/assets/50390141/e9e10f0e-887a-4b27-a9f9-d6ce58bb3ea3)


<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

<!-- Explain the motivation for this PR. Include "Fixes #<number>" if
applicable. -->

## Test plan

<!-- Provide a minimal but complete code snippet that can be used to
test out this change along with instructions how to run it and a
description of the expected behavior. -->

---------

Co-authored-by: Michał Bert <63123542+m-bert@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

5 participants