Native Plugin
An app with a native plugin of its own, in native/greeter. It has:
- a
Greetermodule, which answers from Swift or Kotlin - a
<native-switch>element, drawn by UIKit'sUISwitchand Android'sSwitch - a
<native-sheet>element, which shows the Angular elements inside it in UIKit's sheet and Material'sBottomSheetDialog
Flip the switch, and Angular hears it. Tap the button, and Angular turns it off. Open the sheet, and its counter counts your taps.
The preview has no native code. So there, the module's call fails and the switch is an empty element.
What it shows
nativePluginsin angular.json — the plugin's folder,native/greeter, and the module's and the elements' classes on each platform. See Add native code.NativeModuleMap—greeter.tstypes the module, sogetNativeModule('Greeter')returns a typed proxy whose call is a promise.registerNativeElement()—native-switch.tshas the runtime create the plugin's element for the tag, and types itscheckedattribute and itschangeevent.- The plugin's own resources — the switch is on in the plugin's color, light and dark. See Add resources.
- iOS: a color set in
ios/Greeter.xcassets. - Android:
android/res'svalues/andvalues-night/colors, with the color state lists incolor/thatR.color.greeter_switch_thumbnames.
- iOS: a color set in
HostElementUI—NativeSheet.swiftandNativeSheet.ktmove the element's children into the system's sheet, where their taps still reach Angular. See Show an element's children in a sheet.
Run it with ng build --platform ios --run or --platform android --run. In the preview and in Lynx Explorer, the plugin isn't there.
