Module: RubyNative::Helper

Defined in:
lib/ruby_native/helper.rb

Defined Under Namespace

Classes: NavbarBuilder, NavbarMenuBuilder

Instance Method Summary collapse

Instance Method Details

#native_back_button_tag(text = nil, **options) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/ruby_native/helper.rb', line 16

def native_back_button_tag(text = nil, **options)
  options[:class] = [options[:class], "native-back-button"].compact.join(" ")
  default_content = tag.svg(
    tag.path(d: "M15.75 19.5L8.25 12l7.5-7.5", stroke_linecap: "round", stroke_linejoin: "round"),
    width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", stroke_width: 2.5
  )
  tag.button(text || default_content, onclick: "RubyNative.postMessage({action: 'back'})", **options)
end

#native_badge_tag(count = nil, home: nil, tab: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/ruby_native/helper.rb', line 25

def native_badge_tag(count = nil, home: nil, tab: nil)
  home = count if count && home.nil?
  tab = count if count && tab.nil?

  data = { native_badge: "" }
  data[:native_badge_home] = home unless home.nil?
  data[:native_badge_tab] = tab unless tab.nil?

  tag.div(data: data, hidden: true)
end

#native_fab_tag(icon:, href: nil, click: nil) ⇒ Object



43
44
45
46
47
48
# File 'lib/ruby_native/helper.rb', line 43

def native_fab_tag(icon:, href: nil, click: nil)
  data = { native_fab: true, native_icon: icon }
  data[:native_href] = href if href
  data[:native_click] = click if click
  tag.div(data: data, hidden: true)
end

#native_form_tagObject



8
9
10
# File 'lib/ruby_native/helper.rb', line 8

def native_form_tag
  tag.div(data: { native_form: true }, hidden: true)
end

#native_haptic_data(feedback = :success, **data) ⇒ Object



54
55
56
57
58
59
# File 'lib/ruby_native/helper.rb', line 54

def native_haptic_data(feedback = :success, **data)
  feedback = feedback.to_s
  feedback = "success" if feedback.empty?
  data[:native_haptic] = feedback
  data
end

#native_navbar_tag(title = nil, &block) ⇒ Object



36
37
38
39
40
41
# File 'lib/ruby_native/helper.rb', line 36

def native_navbar_tag(title = nil, &block)
  builder = NavbarBuilder.new(self)
  capture(builder, &block) if block

  tag.div(data: { native_navbar: title.to_s }, hidden: true) { builder.to_html }
end

#native_overscroll_tag(top:, bottom: nil) ⇒ Object



50
51
52
# File 'lib/ruby_native/helper.rb', line 50

def native_overscroll_tag(top:, bottom: nil)
  tag.div(data: { native_overscroll_top: top, native_overscroll_bottom: bottom || top }, hidden: true)
end

#native_push_tagObject



12
13
14
# File 'lib/ruby_native/helper.rb', line 12

def native_push_tag
  tag.div(data: { native_push: true }, hidden: true)
end

#native_tabs_tag(enabled: true) ⇒ Object



3
4
5
6
# File 'lib/ruby_native/helper.rb', line 3

def native_tabs_tag(enabled: true)
  return "".html_safe unless enabled
  tag.div(data: { native_tabs: true }, hidden: true)
end