PeterStaev / nativescript-image-swipe

A NativeScript widget to easily :point_up_2: and :mag: through a list of images
Apache License 2.0
35 stars 21 forks source link

Allow for Safe Area Insets for iPhone X, etc. #35

Closed etelford closed 5 years ago

etelford commented 5 years ago

This fixes a bug on iPhones with Safe Area Insets (iPhone X, Xs, Xs max, etc.) where by just using utils.layout.toDeviceIndependentPixels(this.getMeasuredWidth()); to calculate the width prevents you from scrolling completely through a group of image items.

For example, I had 14 images in my items and after scrolling to the 12th image, I was only able to scroll half way to the 13th image.

My fix involves using getSafeAreaInsets(). On devices without Safe Area Insets, this will return { left: 0, top: 0, right: 0, bottom: 0 }, but on devices with a Safe Are Inset these values will be > 0. On iPhone Xs max, the left is 132. Running this through utils.layout.toDeviceIndependentPixels() on this device will result in 44, which is half of the width we need to account for.

I'm not sure if Android would need a similar affordance. Maybe someone with more Android experience can weigh in.

PeterStaev commented 5 years ago

Hey @etelford , thanks for this contribution!

The current version of the plugin is set to build with TNS 4.0. So the build fails as this method is not present. Please adjust tns-core-modules and tns-platform-declarations to 5.0.0 so the build and CI can succeed.

etelford commented 5 years ago

@PeterStaev Thanks for catching that. I adjusted the versions to 5.0.0, but CI is still failing due to __native not being found in image-swipe.android.ts. I'm happy to change these instances to native if you'd like, but I'm not sure if that's the fix needed. Please let me know what you think.

PeterStaev commented 5 years ago

@etelford __native() should be replaced with global.__native()

etelford commented 5 years ago

@PeterStaev Looks like everything is passing now. Thanks for the guidance.