# `mix dala.enable`
[🔗](https://github.com/manhvu/dala_dev/blob/main/lib/mix/tasks/dala.enable.ex#L1)

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

## Usage

    mix dala.enable FEATURE [FEATURE ...]

Multiple features can be enabled in a single command:

    mix dala.enable camera photo_library
    mix dala.enable camera photo_library file_sharing liveview

## Features

### `liveview`

Enables LiveView mode — the Dala 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>/dala_screen.ex` — a `Dala.Screen` that opens a WebView
    at `http://127.0.0.1:PORT/`
  - Injects the `DalaHook` LiveView hook into `assets/js/app.js`
  - Injects a hidden `<div id="dala-bridge" phx-hook="DalaHook">` into
    `root.html.heex` — **this is required for the hook to mount**
  - Updates `dala.exs` with `liveview_port` so `Dala.Platform.LiveView.local_url/1` works

### Why the hidden div is required

Phoenix LiveView hooks only execute when a DOM element carrying
`phx-hook="DalaHook"` exists in the rendered page. Registering `DalaHook` in
`app.js` is necessary but not sufficient — without a matching DOM element the
hook never mounts and `window.dala` 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 `DalaDev.Enable` module doc and `guides/liveview.md` for the full
two-bridge architecture explanation.

After running:

  1. Add `MyApp.DalaScreen` to your supervision tree (or call
     `Dala.Screen.start_root(MyApp.DalaScreen)` from your `Dala.App.on_start/0`)
  2. Ensure Phoenix is running on the port set in `dala.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+)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
