ruby_native 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/app/controllers/ruby_native/config_controller.rb +1 -0
- data/app/javascript/ruby_native/bridge/haptic_controller.js +11 -0
- data/app/javascript/ruby_native/bridge/index.js +2 -0
- data/lib/generators/ruby_native/templates/ruby_native.yml +1 -0
- data/lib/ruby_native/engine.rb +6 -0
- data/lib/ruby_native/helper.rb +19 -3
- data/lib/ruby_native/tunnel_cookie_middleware.rb +45 -0
- data/lib/ruby_native/version.rb +1 -1
- data/lib/ruby_native.rb +1 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 71ff1f8889c08bae63cda63f21bacdbb89b6ecb2c0e9fca1bcea72e8f47a96e4
|
|
4
|
+
data.tar.gz: ae7319eec1a4a7c27cc539c4a7519cd8fed8e8cf6f7a74c895492751f5c7b524
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 23717abe10128f3e872fb161e7eae5191079b1fb4767ed6b832b3c70f5c04c8773266e8f462fcd349a39a6bbd11df73c53f63ef56fd29da6601adc7ec5bb52c5
|
|
7
|
+
data.tar.gz: '08948c2b203c8d0b966c07eb018555748119fa1a4370c0ed712bce64ed04a86ce5f8ade8c837d89ffe5a8ae48ed435ba56eb6c59630243df7d448e47e9c0a2b9'
|
data/README.md
CHANGED
|
@@ -36,7 +36,7 @@ appearance:
|
|
|
36
36
|
tint_color: "#4F46E5"
|
|
37
37
|
background_color: "#FFFFFF"
|
|
38
38
|
status_bar_color: "#FFFFFF"
|
|
39
|
-
tabs:
|
|
39
|
+
tabs: # optional
|
|
40
40
|
- title: Home
|
|
41
41
|
path: /
|
|
42
42
|
icon: house
|
|
@@ -45,6 +45,8 @@ tabs:
|
|
|
45
45
|
icon: person
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
You may also omit `tabs` to hide the tab bar entirely. The app will load `entry_path` or fall back to `/`.
|
|
49
|
+
|
|
48
50
|
Color fields accept a plain hex string or an object with `light` and `dark` keys for dark mode:
|
|
49
51
|
|
|
50
52
|
```yaml
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BridgeComponent } from "@hotwired/hotwire-native-bridge"
|
|
2
|
+
|
|
3
|
+
export default class extends BridgeComponent {
|
|
4
|
+
static component = "haptic"
|
|
5
|
+
static values = { feedback: { type: String, default: "success" } }
|
|
6
|
+
|
|
7
|
+
vibrate() {
|
|
8
|
+
const feedback = this.feedbackValue || "success"
|
|
9
|
+
this.send("vibrate", { feedback })
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -5,6 +5,7 @@ import PushController from "ruby_native/bridge/push_controller"
|
|
|
5
5
|
import MenuController from "ruby_native/bridge/menu_controller"
|
|
6
6
|
import SearchController from "ruby_native/bridge/search_controller"
|
|
7
7
|
import ButtonController from "ruby_native/bridge/button_controller"
|
|
8
|
+
import HapticController from "ruby_native/bridge/haptic_controller"
|
|
8
9
|
|
|
9
10
|
application.register("bridge--tabs", TabsController)
|
|
10
11
|
application.register("bridge--form", FormController)
|
|
@@ -12,3 +13,4 @@ application.register("bridge--push", PushController)
|
|
|
12
13
|
application.register("bridge--menu", MenuController)
|
|
13
14
|
application.register("bridge--search", SearchController)
|
|
14
15
|
application.register("bridge--button", ButtonController)
|
|
16
|
+
application.register("bridge--haptic", HapticController)
|
|
@@ -6,6 +6,7 @@ appearance:
|
|
|
6
6
|
tint_color: "#007AFF"
|
|
7
7
|
background_color: "#FFFFFF"
|
|
8
8
|
status_bar_color: "#F8F9FA"
|
|
9
|
+
# edge_to_edge: true # Let the web view extend behind the status bar (Normal Mode only)
|
|
9
10
|
# Dark mode example (replace the plain strings above):
|
|
10
11
|
# background_color:
|
|
11
12
|
# light: "#FFFFFF"
|
data/lib/ruby_native/engine.rb
CHANGED
|
@@ -32,6 +32,12 @@ module RubyNative
|
|
|
32
32
|
app.middleware.insert_before ActionDispatch::Cookies, RubyNative::OAuthMiddleware
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
initializer "ruby_native.tunnel_cookie_middleware" do |app|
|
|
36
|
+
if Rails.env.development?
|
|
37
|
+
app.middleware.insert_before ActionDispatch::Cookies, RubyNative::TunnelCookieMiddleware
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
35
41
|
initializer "ruby_native.routes" do |app|
|
|
36
42
|
app.routes.prepend do
|
|
37
43
|
mount RubyNative::Engine, at: "/native"
|
data/lib/ruby_native/helper.rb
CHANGED
|
@@ -11,8 +11,8 @@ module RubyNative
|
|
|
11
11
|
tag.div(data: { native_form: true }, hidden: true)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def native_form_data
|
|
15
|
-
|
|
14
|
+
def native_form_data(**data)
|
|
15
|
+
merge_controller(data, "bridge--form")
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def native_submit_data
|
|
@@ -32,7 +32,7 @@ module RubyNative
|
|
|
32
32
|
tag.path(d: "M15.75 19.5L8.25 12l7.5-7.5", stroke_linecap: "round", stroke_linejoin: "round"),
|
|
33
33
|
width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", stroke_width: 2.5
|
|
34
34
|
)
|
|
35
|
-
tag.button(text || default_content, onclick: "
|
|
35
|
+
tag.button(text || default_content, onclick: "RubyNative.postMessage({action: 'back'})", **options)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def native_search_tag
|
|
@@ -59,6 +59,22 @@ module RubyNative
|
|
|
59
59
|
}) { builder.to_html }
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
+
def native_haptic_data(feedback = :success, **data)
|
|
63
|
+
feedback = feedback.to_s
|
|
64
|
+
feedback = "success" if feedback.empty?
|
|
65
|
+
|
|
66
|
+
data[:native_haptic] = feedback
|
|
67
|
+
data[:bridge__haptic_feedback_value] = feedback
|
|
68
|
+
merge_controller(data, "bridge--haptic")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def merge_controller(data, controller)
|
|
74
|
+
data[:controller] = [data[:controller], controller].compact.join(" ")
|
|
75
|
+
data
|
|
76
|
+
end
|
|
77
|
+
|
|
62
78
|
class MenuBuilder
|
|
63
79
|
def initialize(context)
|
|
64
80
|
@context = context
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module RubyNative
|
|
2
|
+
# Strips the `domain=` attribute from Set-Cookie headers when the request
|
|
3
|
+
# comes through a Cloudflare tunnel (*.trycloudflare.com).
|
|
4
|
+
#
|
|
5
|
+
# Many Rails apps configure `domain: :all, tld_length: 2` on their session
|
|
6
|
+
# store. Through a tunnel this resolves to `.trycloudflare.com`, a public
|
|
7
|
+
# suffix domain. Browsers and WKWebView silently reject those cookies,
|
|
8
|
+
# breaking authentication.
|
|
9
|
+
#
|
|
10
|
+
# Removing the domain attribute lets the cookie scope to the exact tunnel
|
|
11
|
+
# hostname (e.g. `abc-123.trycloudflare.com`) so it persists normally.
|
|
12
|
+
class TunnelCookieMiddleware
|
|
13
|
+
TUNNEL_HOST_PATTERN = /\.trycloudflare\.com\z/
|
|
14
|
+
|
|
15
|
+
def initialize(app)
|
|
16
|
+
@app = app
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def call(env)
|
|
20
|
+
status, headers, body = @app.call(env)
|
|
21
|
+
|
|
22
|
+
if tunnel_request?(env) && headers["set-cookie"]
|
|
23
|
+
strip_cookie_domain!(headers)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
[status, headers, body]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def tunnel_request?(env)
|
|
32
|
+
host = env["HTTP_HOST"] || env["SERVER_NAME"] || ""
|
|
33
|
+
host.match?(TUNNEL_HOST_PATTERN)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def strip_cookie_domain!(headers)
|
|
37
|
+
raw = headers["set-cookie"]
|
|
38
|
+
cookies = raw.is_a?(Array) ? raw : raw.split("\n")
|
|
39
|
+
|
|
40
|
+
headers["set-cookie"] = cookies.map { |cookie|
|
|
41
|
+
cookie.gsub(/;\s*domain=[^;]*/i, "")
|
|
42
|
+
}.join("\n")
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/ruby_native/version.rb
CHANGED
data/lib/ruby_native.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby_native
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joe Masilotti
|
|
@@ -56,6 +56,7 @@ files:
|
|
|
56
56
|
- app/javascript/ruby_native/back.js
|
|
57
57
|
- app/javascript/ruby_native/bridge/button_controller.js
|
|
58
58
|
- app/javascript/ruby_native/bridge/form_controller.js
|
|
59
|
+
- app/javascript/ruby_native/bridge/haptic_controller.js
|
|
59
60
|
- app/javascript/ruby_native/bridge/index.js
|
|
60
61
|
- app/javascript/ruby_native/bridge/menu_controller.js
|
|
61
62
|
- app/javascript/ruby_native/bridge/push_controller.js
|
|
@@ -79,6 +80,7 @@ files:
|
|
|
79
80
|
- lib/ruby_native/native_detection.rb
|
|
80
81
|
- lib/ruby_native/native_version.rb
|
|
81
82
|
- lib/ruby_native/oauth_middleware.rb
|
|
83
|
+
- lib/ruby_native/tunnel_cookie_middleware.rb
|
|
82
84
|
- lib/ruby_native/version.rb
|
|
83
85
|
homepage: https://github.com/Ruby-Native/gem
|
|
84
86
|
licenses:
|