Skip to content

Reset method performance issue #88

Description

@arslc

Hello, can anyone create PR with this changes?

https://github.com/pavelbabenko/react-native-awesome-gallery/blob/main/src/index.tsx?plain=1#L236

Original
const resetValues = (animated = true) => {
  'worklet';
  
  scale.value = animated ? withTiming(1) : 1;
  offset.x.value = animated ? withTiming(0) : 0;
  offset.y.value = animated ? withTiming(0) : 0;
  translation.x.value = animated ? withTiming(0) : 0;
  translation.y.value = animated ? withTiming(0) : 0;
};
Modified
const resetValues = (animated = true) => {
  'worklet';
  
  const resetProperty = (prop, target) => {
    if (prop.value !== target) prop.value = animated ? withTiming(target) : target;
  };
  
  resetProperty(scale, 1);
  resetProperty(offset.x, 0);
  resetProperty(offset.y, 0);
  resetProperty(translation.x, 0);
  resetProperty(translation.y, 0);
};

Original code has problem this performance (update every image even if they are already set to their target values)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions