Skip to content

Instantly share code, notes, and snippets.

@shirakaba
Last active March 2, 2019 19:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirakaba/cc86fd6cbc7cc72fed76c51881f660bd to your computer and use it in GitHub Desktop.
Save shirakaba/cc86fd6cbc7cc72fed76c51881f660bd to your computer and use it in GitHub Desktop.
NativeScript global-context native APIs

By executing the following code snippet in NS:IDE, we can see which native APIs have been exposed to JS, at least in the global context:

Object.keys(global).sort();

Thus, we can see that the following keys exist on the global object, most of which are iOS APIs. There is also precious little overlap with Node.js's global interface.

[
  "CAAnimationDelegate",
  "CADisplayLink",
  "CALayer",
  "CATransaction",
  "CGAffineTransformMake",
  "CGAffineTransformMakeTranslation",
  "CGDataProviderCreateWithCFData",
  "CGFontCreateWithDataProvider",
  "CGPointMake",
  "CGRect",
  "CGRectEqualToRect",
  "CGRectMake",
  "CGRectZero",
  "CGSize",
  "CGSizeMake",
  "CTFontManagerRegisterGraphicsFont",
  "CodeAttributedString",
  "Deprecated",
  "Experimental",
  "Highlightr", // This is a plugin I added myself.
  "NSArray",
  "NSData",
  "NSDictionary",
  "NSFileManager",
  "NSFontAttributeName",
  "NSForegroundColorAttributeName",
  "NSInvocation",
  "NSLayoutManager",
  "NSMakeRange",
  "NSMethodSignature",
  "NSMutableArray",
  "NSMutableAttributedString",
  "NSNotification",
  "NSNotificationCenter",
  "NSNumber",
  "NSObject",
  "NSString",
  "NSStringFromClass",
  "NSTextContainer",
  "NSURL",
  "ObjC",
  "ObjCClass",
  "ObjCMethod",
  "ObjCParam",
  "System",
  "UIApplication",
  "UIApplicationDidBecomeActiveNotification",
  "UIApplicationDidEnterBackgroundNotification",
  "UIApplicationDidFinishLaunchingNotification",
  "UIApplicationDidReceiveMemoryWarningNotification",
  "UIApplicationMain",
  "UIApplicationWillTerminateNotification",
  "UIBarButtonItem",
  "UIButton",
  "UIColor",
  "UIDevice",
  "UIDeviceOrientationDidChangeNotification",
  "UIDocumentInteractionControllerDelegate",
  "UIEdgeInsetsMake",
  "UIFont",
  "UIFontDescriptor",
  "UIFontDescriptorFamilyAttribute",
  "UIFontDescriptorTraitsAttribute",
  "UIFontSymbolicTrait",
  "UIFontWeightRegular",
  "UIFontWeightTrait",
  "UIGestureRecognizer",
  "UIGestureRecognizerDelegate",
  "UIImage",
  "UILabel",
  "UILayoutGuide",
  "UINavigationBar",
  "UINavigationController",
  "UINavigationControllerDelegate",
  "UINavigationItem",
  "UINode",
  "UIResponder",
  "UIScreen",
  "UIScreenEdgePanGestureRecognizer",
  "UIScrollView",
  "UIScrollViewDelegate",
  "UITabBar",
  "UITabBarController",
  "UITabBarControllerDelegate",
  "UITabBarItem",
  "UITableViewCell",
  "UITableViewDataSource",
  "UITableViewDelegate",
  "UITextView",
  "UITextViewDelegate",
  "UIView",
  "UIViewController",
  "UIViewControllerAnimatedTransitioning",
  "UIWindow",
  "WeakRef",
  "Worker",
  "__assign",
  "__asyncDelegator",
  "__asyncGenerator",
  "__asyncValues",
  "__await",
  "__awaiter",
  "__decorate",
  "__exportStar",
  "__generator",
  "__importDefault",
  "__importStar",
  "__makeTemplateObject",
  "__metadata",
  "__onLiveSync",
  "__onLiveSyncCore",
  "__onUncaughtError",
  "__param",
  "__read",
  "__rest",
  "__spread",
  "__values",
  "app", // I added this; it is a reference to the app root. 
  "design", // I added this; it is a reference to a view.
  "loadModule",
  "moduleExists",
  "moduleMerge",
  "moduleResolvers",
  "registerModule",
  "registerWebpackModules",
  "webpackJsonp",
  "zonedCallback"
]

It's clear that most of these APIs are from UIKit, or correspond to fundamental data types (which I've tracked down to inlineFunctions.js).

However, there are a lot more hiding that don't show up as keys on global. For example, global.AVCaptureDevice (also accessible as just AVCaptureDevice)...

You can see many properties are added in GlobalObject.mm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment