Skip to content

Commit 13bb922

Browse files
committed
rename data_frais_action to data_frails_navigation
1 parent 66f6e3d commit 13bb922

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

example/lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ import 'package:flutter_on_rails/flutter_on_rails.dart';
44
void main() async {
55
WidgetsFlutterBinding.ensureInitialized();
66
await init();
7-
runApp(MaterialApp(home: MainScreen(url: "http://172.20.10.12:3000")));
7+
runApp(MaterialApp(home: MainScreen()));
88
}
9+
// url: "http://172.20.10.12:3000"

lib/src/Widget/main/main_screen.dart

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,6 @@ class _MainScreenState extends State<MainScreen> {
168168
SystemChannels.textInput.invokeMethod('TextInput.show');
169169
},
170170
);
171-
// Inject keyboard focus handling JavaScript
172-
await provider.state.controller!.evaluateJavascript(
173-
source: """
174-
(function() {
175-
document.addEventListener('focus', function(e) {
176-
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') {
177-
window.flutter_on_rails.callHandler('inputFocus');
178-
}
179-
}, true);
180-
})();
181-
""",
182-
);
183171
},
184172
onLoadStart: (controller, url) async {
185173
// Set appropriate user agent for the URL
@@ -213,23 +201,7 @@ class _MainScreenState extends State<MainScreen> {
213201
provider.setLoading(false);
214202
final currentUrl = await controller.getUrl();
215203
provider.setCurrentUrl(currentUrl.toString());
216-
await provider.state.controller!.evaluateJavascript(
217-
source: """
218-
(function() {
219-
document.addEventListener("click", function(event) {
220-
// Correct selector for data_frails_action (with an underscore)
221-
const link = event.target.closest("a[data_frails_action]");
222-
console.log("Link clicked:", link); // Check if the link is found
223-
if (!link) return;
224-
const action = link.getAttribute("data_frails_action");
225-
console.log("Action:", action);
226-
if (window.flutter_on_rails) {
227-
window.flutter_on_rails.callHandler('actionHandler', action);
228-
}
229-
});
230-
})();
231-
""",
232-
);
204+
await RunJs().handleNav(provider);
233205
await RunJs().runJavaScriptAndHideBottomNav(provider);
234206
},
235207
onUpdateVisitedHistory: (controller, url, isReload) async {

lib/src/services/run_js.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,37 @@ class RunJs {
136136
debugPrint('Error in handleForm: \$e');
137137
}
138138
}
139+
140+
handleNav(AppNotifier provider) {
141+
provider.state.controller!.evaluateJavascript(
142+
source: """
143+
(function() {
144+
document.addEventListener("click", function(event) {
145+
// Correct selector for data_frails_action (with an underscore)
146+
const link = event.target.closest("a[data_frails_navigation]");
147+
console.log("Link clicked:", link); // Check if the link is found
148+
if (!link) return;
149+
const action = link.getAttribute("data_frails_navigation");
150+
console.log("Action:", action);
151+
if (window.flutter_on_rails) {
152+
window.flutter_on_rails.callHandler('actionHandler', action);
153+
}
154+
});
155+
})();
156+
""",
157+
);
158+
}
159+
160+
// Inject keyboard focus handling JavaScript
161+
// await provider.state.controller!.evaluateJavascript(
162+
// source: """
163+
// (function() {
164+
// document.addEventListener('focus', function(e) {
165+
// if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') {
166+
// window.flutter_on_rails.callHandler('inputFocus');
167+
// }
168+
// }, true);
169+
// })();
170+
// """,
171+
// );
139172
}

0 commit comments

Comments
 (0)