mix mob.enable (mob_dev v0.3.37)

Copy Markdown View Source

Enables one or more optional Mob features by patching mix.exs, manifest files, and generating any required source files.

Usage

mix mob.enable FEATURE [FEATURE ...]

Multiple features can be enabled in a single command:

mix mob.enable camera photo_library
mix mob.enable camera photo_library file_sharing liveview

Features

liveview

Enables LiveView mode — the Mob app runs a local Phoenix endpoint and displays it in a native WebView. Web developers can ship a mobile app with zero native UI code.

What it does:

  • Generates lib/<app>/mob_screen.ex — a Mob.Screen that opens a WebView at http://127.0.0.1:PORT/
  • Injects the MobHook LiveView hook into assets/js/app.js
  • Injects a hidden <div id="mob-bridge" phx-hook="MobHook"> into root.html.heexthis is required for the hook to mount
  • Updates mob.exs with liveview_port so Mob.LiveView.local_url/1 works

Why the hidden div is required

Phoenix LiveView hooks only execute when a DOM element carrying phx-hook="MobHook" exists in the rendered page. Registering MobHook in app.js is necessary but not sufficient — without a matching DOM element the hook never mounts and window.mob is never replaced with the LiveView-backed version. Messages would silently route through the native NIF bridge instead of the LiveView WebSocket, so handle_event/3 would never fire.

See MobDev.Enable module doc and guides/liveview.md for the full two-bridge architecture explanation.

After running:

  1. Add MyApp.MobScreen to your supervision tree (or call Mob.Screen.start_root(MyApp.MobScreen) from your Mob.App.on_start/0)
  2. Ensure Phoenix is running on the port set in mob.exs (default: 4000)

camera

Adds camera permission declarations to platform manifests.

  • iOS: adds NSCameraUsageDescription to ios/*/Info.plist
  • Android: adds <uses-permission android:name="android.permission.CAMERA"/> to android/app/src/main/AndroidManifest.xml

photo_library

  • iOS: adds NSPhotoLibraryAddUsageDescription to Info.plist
  • Android: no manifest change needed (API 29+)

file_sharing

  • iOS: adds UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace to Info.plist
  • Android: adds <provider android:name="FileProvider"> with paths config

location

  • iOS: adds NSLocationWhenInUseUsageDescription to Info.plist
  • Android: adds ACCESS_FINE_LOCATION permission

notifications

  • iOS: runtime only — no plist key needed
  • Android: adds POST_NOTIFICATIONS permission (API 33+)