Skip to content

Add basic camera feed #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 9, 2025
Merged

Add basic camera feed #3

merged 3 commits into from
Feb 9, 2025

Conversation

leonvogt
Copy link
Owner

@leonvogt leonvogt commented Feb 9, 2025

This PR contains the full code from the blog post: https://leonvogt.com/hotwire-native-camera-access

@leonvogt leonvogt merged commit 2b783e6 into main Feb 9, 2025
@leonvogt leonvogt mentioned this pull request Feb 9, 2025
@leonvogt leonvogt deleted the add-basic-camera-feed branch February 9, 2025 09:59
@preconcurrency import WebKit
import HotwireNative

class CustomWKUIController: NSObject, WKUIDelegate {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I've made a mistake here!
If we create our own WKUIController like this, we will lose the built-in alert() and prompt() functionality that Hotwire provides.
Therefore, we should subclass Hotwire Native's WKUIController here.
Thanks to @joemasilotti for pointing this out!

- class CustomWKUIController:  NSObject, WKUIDelegate {
+ class CustomWKUIController: WKUIController {
@@ -11,6 +11,7 @@ class HotwireCentral {
private init() {
configureHotwire()
self.navigator = Navigator()
self.navigator.webkitUIDelegate = CustomWKUIController()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we should subclass Hotwire Native's WKUIController, we need to forward the navigator instance as a WKUIControllerDelegate to CustomWKUIController.

- self.navigator.webkitUIDelegate = CustomWKUIController()
+ self.navigator.webkitUIDelegate = CustomWKUIController(delegate: navigator)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant