For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/embedding/index.md.

Embed in an existing native app

Already have an iOS or Android app? Show your Angular app as one or more screens inside it. You don't have to ship the app that ng build --platform generates.

This page needs native code

Embedding means changing your iOS or Android project, in Swift, Objective-C, Kotlin or Java. It's the one place in these docs where you need native knowledge. Work through it with whoever maintains your native app.

How it fits together

Your native app adds the Lynx engine. It shows your bundle in a LynxView: a native view that runs a Lynx bundle, like an <iframe> for Lynx content. You place a LynxView in your own screens, as you would any other native view.

Your native app becomes the host app: the app that loads your bundle and shows it. Build the bundle with plain ng build, as in Build your app.

Add Lynx to your app

Lynx's guides cover the native setup:

The apps ng build --platform generates use Lynx 4.1.0, the version AngularLynx is tested with.

What your app must do

Beyond Lynx's own setup, your app has three jobs:

  1. Load the bundle
  2. Serve static/
  3. Link XElement

Load the bundle

The Lynx engine doesn't fetch bundles itself. Your app gives it a loader that reads them, from the app or from the network:

  • iOS: a LynxTemplateProvider
  • Android: an AbsTemplateProvider

Lynx's integration guide shows one for each platform.

Serve static/

Images and fonts your code imports load from /static/... paths. Pick one:

  • Ship static/ inside your app, and resolve /static/... paths against where you keep it. The generated apps do this.
  • Host it on a server, and set RSpeedy's output.assetPrefix to its URL:
lynx.config.ts
import { defineConfig } from '@blotch/angular-lynx-build';

export default defineConfig({
  output: { assetPrefix: 'https://cdn.example.com/my-app/' },
});
Link XElement, or some elements render nothing

Some elements aren't part of Lynx's core. They come from Lynx's XElement library: <input>, <textarea>, <overlay>, <svg>, <blur-view>, <viewpager>, <refresh>, the <scroll-coordinator> family, <webview> and <video>.

An app that doesn't link XElement and register its elements renders nothing for these tags. On Android, the elements after them can disappear too. Nothing on screen says why.

  • Android: add org.lynxsdk.lynx:xelement, and call addBehaviors(XElementBehaviors().create()) on the LynxViewBuilder.
  • iOS: add the XElement pod.

Lynx's integration guide has the details. The apps ng build --platform generates already do this, and so does Lynx Explorer.

Bundled or downloaded

Your app can ship the bundle inside it, or download it from a server:

StrategyProsCons
Bundled: ship it inside the appLoads instantly, works offlineChanging the app needs a store update
Downloaded: host it on a server/CDNUpdate without a store release, run A/B testsNeeds the network, at least on first launch

You can combine both. Ship a bundle with the app for an instant first launch, then check for a newer one in the background.

Before you serve updates this way:

  • Match the Lynx version. A bundle only runs on a Lynx engine at least as new as its targetSdkVersion. That's an AngularLynx plugin option, which defaults to 3.2. Every installed version of your app must be able to run what you serve. So raise targetSdkVersion only when every installed version's engine is that new.
  • Check the store rules. Both stores have rules about code an app downloads after review. Read Apple's App Review Guidelines and Google Play's Developer Program Policies before you rely on it.

Copy the iOS extras

The iOS app ng build --platform ios generates adds two things XElement lacks. Copy them to get the same in your app.

Glass that blurs and morphs

XElement's <blur-view> falls short of the glass components:

The generated app adds both with a <blur-view> of its own, BlurView.swift, and the GlassTransitions.swift it uses. To get them:

  1. Copy both files into your app.
  2. Register BlurView for blur-view, in place of XElement's LynxUIBlurView.

Without them, the components draw Lynx's older blur instead, and their glass comes and goes at once.

Web views that go away

On iOS, XElement's <webview> keeps its web view after the element goes. The WebContent process WebKit started for it stays too. So every <webview> your app shows stays for as long as the app runs, because its loader and its web view keep each other.

The generated app wraps XElement's loader so the web view goes with the element, in WebViewLoader.swift. To get it:

  1. Copy the file into your app.
  2. Call ShellWebViewLoaderProvider.register() before your first LynxView, where you register XElement's elements.

Connect more native features

Some AngularLynx services call native code in the host app. The generated apps have all of it. In your own app, add what you use: