ascoders / react-native-image-zoom

react native image pan and zoom
MIT License
637 stars 282 forks source link

Allow zero for `duration` parameter for centerOn method #158

Open Sc4ramouche opened 3 years ago

Sc4ramouche commented 3 years ago

Hi there! First of all, thanks for maintaining this cool project! 💪

This pull request aims to allow developers to specify 0 as a valid value for the duration parameter passed to centerOn method. Currently, specifying 0 leads to having 300 as a fallback value due to the fact that zero is treated as a falsy value, thus the expression 0 || 300 returns 300. In our use case, it is required just to show part of the big image, and animation is unnecessary in the scenario we try to implement. My intuition was to just specify zero for the duration parameter, but it didn't work. To achieve the desired outcome I currently need to specify 1 or 0.1 as animation duration, which is, in my opinion, might be a bit confusing for newcomers.

I think we could utilize nullish coalescing here. Luckily, there's no additional configuration required as TypeScript 3.9.2 already supports it.

Please, let me know what do you think about this!

Sc4ramouche commented 3 years ago

My bad, I didn't really put the effort to look through existing pull requests. #147 already solves the problem I'm facing. Nevertheless, this PR solves it in a bit different manner. Feel free to close this PR in case you merge #147.