nirsky / react-native-size-matters

A lightweight, zero-dependencies, React-Native utility belt for scaling the size of your apps UI across different sized devices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rounding the output from scale

richardhyatt opened this issue · comments

Have you considered rounding the result from scale()?

I love this module, but I find that sometimes under the right circumstances, the scaled value causes issues (gaps between components) when used to determine padding amounts on a component. After spending some time investigating, I noticed that if the result was rounded (to the nearest pixel), the issues went away. This could break other implementations that depend on the multiple decimal places of subpixels, thus it could be implemented as a separate set of exports.

Hey @richardhyatt,
Let me think that through, I had some issues regarding this before so maybe it's time to consider this.
I'll update.

Added round functionality for ScaledSheet on version 0.3.0.
PR #34.

To round without ScaledSheet, simply apply Math.round on the scaling function result.
example:

const style = {
    width: Math.round(scale(100))
}