Getting Platform Specific in NativeScript
Have you ever written platform specific code in NativeScript, whether it was JavaScript or CSS? Did it look like a giant -- statement? Or…
Take control of your career. Build JavaScript mobile apps.
Catch Dave Coffin, Nathan Walker, and Alex Ziskind at ngAtlanta in February 2020 for an advanced NativeScript with Angular workshop called Breathe life into mobile UX with solid architecture lessons
. You can register now and take your NativeScript skills up a notch. Register here.
Have you ever written platform specific code in NativeScript, whether it was JavaScript or CSS?
Did it look like a giant if
-then
-else
statement? Or maybe you even separated out your platform specific code into separate functions, but you still needed conditional statements and your code for iOS and Android still gets packaged up whether it’s destined for one platform or another. In this series of videos, I’ll show you how to avoid doing this altogether and get only the code you need for a specific platform packaged, all while using clean interfaces and TypeScript.
Tip #1 - Classes
In this first video of the series, I show you how to separate out your platform specific code using TypeScript classes. If you need to execute different code paths on iOS and Android, and you need to encapsulate your logic using a class, this video shows you how to do it.
Tip #2 - Functions
In this second video of the series, I show you how to execute different code while calling a single function. If you need to execute different code on iOS and Android, but you’re using a functional approach, or you have some utility function, and don’t need to create a class, then this video shows you how.
Tip #3 - CSS
In this third video of the series, I show you how the best way I found so far to separate out your platform specific CSS code, while still allowing for code reuse of the styles that are shared between platforms.
I hope you enjoy the series, and let me know (@digitalix on Twitter) if you have a specific need for code separation or you want to see a video of a different case that’s not covered in this series yet.