<commit_before>import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { Animated } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';
import * as Animatable from 'react-native-animatable';
import PXTouchable from './PXTouchable';
import { LIKE_BUTTON_ACTION_TYPES } from '../common/constants';

const AnimatableIcon = Animatable.createAnimatableComponent(Icon);

class BookmarkButton extends Component {
  static propTypes = {
    item: PropTypes.object.isRequired,
    onPress: PropTypes.func.isRequired,
    onLongPress: PropTypes.func.isRequired,
  };

  constructor(props) {
    const { item } = props;
    super(props);
    this.state = {
      isBookmark: item.is_bookmarked,
      scaleAnim: new Animated.Value(0),
    };
  }

  componentWillReceiveProps(nextProps) {
    const { item: prevItem } = this.props;
    const { item } = nextProps;
    const { isBookmark } = this.state;
    if (
      item.is_bookmarked !== prevItem.is_bookmarked &&
      item.is_bookmarked !== isBookmark
    ) {
      if (item.is_bookmarked && !isBookmark) {
        this.animateBookmark();
      }
      this.setState({
        isBookmark: item.is_bookmarked,
      });
    }
  }

  handleOnPress = () => {
    const { onPress, actionType } = this.props;
    const { isBookmark } = this.state;<commit_msg>Migrate componentWillReceiveProps to componentDidUpdate for bookmark button<commit_after>import React, { Component } from 'react';
import { Animated } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';
import * as Animatable from 'react-native-animatable';
import PXTouchable from './PXTouchable';
import { LIKE_BUTTON_ACTION_TYPES } from '../common/constants';

const AnimatableIcon = Animatable.createAnimatableComponent(Icon);

class BookmarkButton extends Component {
  constructor(props) {
    const { item } = props;
    super(props);
    this.state = {
      isBookmark: item.is_bookmarked,
      scaleAnim: new Animated.Value(0),
    };
  }

  componentDidUpdate(prevProps) {
    const { item } = this.props;
    const { item: prevItem } = prevProps;
    const { isBookmark } = this.state;
    if (
      item.is_bookmarked !== prevItem.is_bookmarked &&
      item.is_bookmarked !== isBookmark
    ) {
      if (item.is_bookmarked && !isBookmark) {
        this.animateBookmark();
      }
      this.setState({
        isBookmark: item.is_bookmarked,
      });
    }
  }

  handleOnPress = () => {
    const { onPress, actionType } = this.props;
    const { isBookmark } = this.state;
{'fraction_non_alphanumeric': 0.11951882033372138, 'fraction_numerical': 0.0007760962359332557, 'mean_word_length': 3.296666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6416883', 'n_tokens_mistral': 808, 'n_tokens_neox': 801, 'n_words': 167}