Android端Hotwire Native路径配置无法触发模态框问题
问题:Android端Hotwire Native无法以模态框打开"new"视图
我希望所有“new”视图都以模态框(Modal)形式打开,但无论如何修改配置,Android端页面始终在新卡片中打开。服务器未出现错误,恳请技术建议。
已尝试的操作
- 验证JSON配置,验证通过。
- 在主机打开
http://localhost:3000/configurations/android_v1.json,JSON可正常渲染。 - 在Android模拟器打开
http://10.0.2.2:3000/configurations/android_v1.json,JSON可正常渲染。
相关代码片段
Rails配置控制器 (app/controllers/configurations_controller.rb)
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
Rails路由配置 (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
Rails列表视图 (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 %>
Android主活动 (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" ) ) } }
内容的提问来源于stack exchange,提问作者Nicklas Niels Jensen
相关产品推荐
相关产品推荐

