Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with NativeScript

You're reading from   Getting Started with NativeScript Explore the possibility of building truly native, cross-platform mobile applications using your JavaScript skill—NativeScript!

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher
ISBN-13 9781785888656
Length 168 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Nathanael J. Anderson Nathanael J. Anderson
Author Profile Icon Nathanael J. Anderson
Nathanael J. Anderson
Arrow right icon
View More author details
Toc

Code differences


In cases where you are coding an Android- or iOS-specific feature or, perhaps, working around an issue on a specific platform, there is an easy technique to determine the platform on every component. Each component that wraps a native component has either an .ios or an .android property that is used to access the actual underlying native component. If we wanted to select all the text inside the myText text box, we can do so as follows:

var myText = frame.topmost().getViewById('myText');
if (myText.android) {
  console.log('We are running on Android');
  myText.android.selectAll();
} else if (myText.ios) {
  console.log("We are running on iOS");
  var range = new NSRange();
  range.location = 0;
  range.length = myText.text.length;
  myText.ios.selectedRange = range;
}

If you want only the code to be executed on iOS, check for the .ios property on the component and then add whatever the specific code is for iOS. On Android, it is the .android property. Each platform has its...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime