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

Fix global config animation durations being ignored if props are not set #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Xmaxer
Copy link

@Xmaxer Xmaxer commented Nov 6, 2023

This will fix an issue where if the animation durations are set in the global config, they are ignored unless an explicit prop is passed.

The problem is that the current implementation does a simple logical OR comparison against the config value if the prop value is undefined, meaning it falls back to 100 ms for the duration of the animation.

Sample code that used to cause the issue:

CacheManager.config = {
  baseDir: `${Dirs.CacheDir}/images_cache/`,
  blurRadius: 0,
  cacheLimit: 1024 * 1024 * 1024,
  maxRetries: 2,
  retryDelay: 1000,
  sourceAnimationDuration: 0,
  thumbnailAnimationDuration: 0,
};

Component usage:

        <CachedImage
          source={imageUrl}
          style={{
            width: '100%',
            height: '100%',
          }}
        />

The fix is to just use the Nullish coalescing operator to compare the values rather than only checking if props set it to zero. So now the priority is props value -> config value -> default (100) as intended.

I've already tested this change in my current project, as well as the example project and it works correctly as far as I can see now.

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.

1 participant