0

I want every "new" views to open in a modal. But no matter what I change, the page keeps opening in a new card on Android. I've tried:

  1. Validated JSON - it passed.
  2. Opened http://localhost:3000/configurations/android_v1.json on host machine - JSON is rendered.
  3. Opened http://10.0.2.2:3000/configurations/android_v1.json on Android emulator - JSON is rendered.

No server errors appears. I'd appreciate inputs. Source files can be viewed here if more code is needed to help:

https://github.com/McNiels100/RD/tree/Hotwire-Native

https://github.com/McNiels100/RD-Android

# app/controllers/configurations_controller
class ConfigurationsController < ApplicationController
  
#...

  def android_v1
    render json: {
      settings: {},
      rules: [
        {
          patterns: [
            ".*"
          ],
          properties: {
            uri: "hotwire://fragment/web",
            pull_to_refresh_enabled: true
          }
        },
        {
          patterns: [
            "/new$",
            "/edit$"
          ],
          properties: {
            context: "modal",
            pull_to_refresh_enabled: false
          }
        }
      ]
    }
  end
end
# config/routes.rb
Rails.application.routes.draw do

  #...

  root "repairs#index"

  resources :repairs do
    member do
      post :add_images
      delete :remove_image
      post :lock
      post :unlock
      post :add_status
      post :add_repair_item
      delete :remove_repair_item
      get :load_inventory
      patch :reopen
    end
  end

#...

  resources :configurations, only: [] do
    get :ios_v1, on: :collection
    get :android_v1, on: :collection
  end
end

# app/views/repairs/index.html.erb
<div class="flex-container content-space-between align-items-center">
  <h1>All open repairs</h1>
  <%= link_to 'New repair', new_repair_path %>
  <%= render 'layouts/filter',
             path: repairs_path,
             device_types_filter: true,
             tat_statuses_filter: true,
             repair_statuses_filter: true,
             brands: @brands,
             device_types: @device_types,
             tat_statuses: RepairsHelper::TAT_STATUSES,
             repair_statuses: Status.active %>
</div>
<%= render 'backlog' %>
<%= render 'layouts/pagination', page: @page, total_pages: @total_pages,
           per_page: @per_page, total_items: @total_items %>
# app/src/main/java/com/mcniels/rd/MainActivity.kt
package com.mcniels.rd

import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import dev.hotwire.core.config.Hotwire
import dev.hotwire.core.turbo.config.PathConfiguration
import dev.hotwire.navigation.activities.HotwireActivity
import dev.hotwire.navigation.navigator.NavigatorConfiguration
import dev.hotwire.navigation.util.applyDefaultImeWindowInsets

const val baseURL = "http://10.0.2.2:3000"

class MainActivity : HotwireActivity() {
    override fun navigatorConfigurations() = listOf(
        NavigatorConfiguration(
            name = "main",
            startLocation = "$baseURL/repairs",
            navigatorHostId = R.id.main
        )
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        findViewById<View>(R.id.main).applyDefaultImeWindowInsets()

        Hotwire.loadPathConfiguration(
            context = this,
            location = PathConfiguration.Location(
                remoteFileUrl = "$baseURL/configurations/android_v1.json"
            )
        )
    }
}

1 Answer 1

1

Path Configuration is not being loaded because it requires authentication. It redirects to new session every time the app is opened.

Add allow_unauthenticated_access to ConfigurationsController.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.