The PathConfiguration
Path Configuration is an essential feature for giving a native look and feel to a Rails application on platforms like iOS and Android, offering extensive possibilities for customization.
It acts as the central source that defines how the native application behaves for each URL. Below, we’ll explore practical scenarios to understand its functionality.
Scenario: Modal Navigation
Modal navigation is a standout feature of the iOS platform. For example, in the Contacts app, clicking the add (+)
button opens a modal over the previous screen. When the modal is closed, the user returns to the previous screen.
In Ruby on Rails applications adapted for native platforms, it’s common for new and edit actions to use modal navigation.
With Path Configuration, the native application can be set up to treat URLs containing /new
or /edit
as modal navigation contexts.
Configuration:
Message for the native app:
Native app, if you're accessing a URL that contains /new or /edit, let's use modal navigation.
Let’s implement this configuration.
Adding the path-configuration.json File
Now, let’s make the initial configurations for PathConfiguration. In the project file tree:
Right-click and select
New Empty
File orCommand + N
.Name the file
path-configuration.json
.Add the following content to the file:
{
"settings": {},
"rules": [
{
"patterns": [ ".*" ],
"properties": {
"context": "default",
"pull_to_refresh_enabled": true
}
},
{
"patterns": [ "/new$", "/edit$" ],
"properties": {
"context": "modal",
"pull_to_refresh_enabled": false
}
}
]
}
Configuring the AppDelegate with PathConfiguration
In Hotwire Native version 1.1.0, you need to adjust the AppDelegate
file to specify the location of the path-configuration.json
file. Add the following configuration inside the application function:
import HotwireNative
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Locate the path-configuration.json file.
Hotwire.loadPathConfiguration(from: [
.file(Bundle.main.url(forResource: "path-configuration", withExtension: "json")!)
])
return true
}
Run the application using Command + R
. Once it loads, navigate to URLs and click on New URL
. The following screens will be displayed:
Clicking on New URL will display a modal, creating a more native experience and improving usability.
The Path Configuration provides various possibilities, including:
Hiding the Navbar or StatusBar.
Adjusting modals as needed.
Disabling stack navigation, which is the default in iOS.
It depends on native implementation with Swift, but it's totally possible.