Class: RubyNative::Helper::NavbarBuilder
- Inherits:
-
Object
- Object
- RubyNative::Helper::NavbarBuilder
- Defined in:
- lib/ruby_native/helper.rb
Instance Method Summary collapse
- #button(title = nil, icon: nil, icons: nil, href: nil, click: nil, position: :trailing, selected: false, &block) ⇒ Object
-
#initialize(context) ⇒ NavbarBuilder
constructor
A new instance of NavbarBuilder.
-
#segment(title, href: nil, click: nil, selected: false) ⇒ Object
Adds a segment to the nav bar.
-
#share_button(url: nil, title: "Share", icon: "square.and.arrow.up", icons: { android: "share" }, position: :trailing) ⇒ Object
Adds a native share button to the nav bar.
- #submit_button(title: "Save", click: "[type='submit']") ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(context) ⇒ NavbarBuilder
Returns a new instance of NavbarBuilder.
268 269 270 271 |
# File 'lib/ruby_native/helper.rb', line 268 def initialize(context) @context = context @items = [] end |
Instance Method Details
#button(title = nil, icon: nil, icons: nil, href: nil, click: nil, position: :trailing, selected: false, &block) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/ruby_native/helper.rb', line 273 def (title = nil, icon: nil, icons: nil, href: nil, click: nil, position: :trailing, selected: false, &block) resolved = RubyNative::Helper.resolve_icon(icon: icon, icons: icons, platform: @context.try(:native_platform)) data = { native_button: "" } data[:native_title] = title if title data[:native_icon] = resolved if resolved data[:native_href] = href if href data[:native_click] = click if click data[:native_position] = position.to_s data[:native_selected] = "" if selected if block = NavbarMenuBuilder.new(@context) @context.capture(, &block) add(@context.tag.div(data: data) { .to_html }) else add(@context.tag.div(data: data)) end end |
#segment(title, href: nil, click: nil, selected: false) ⇒ Object
Adds a segment to the nav bar. On iOS the segments render as a centered
segmented control (the same control the App Store uses for Apps/Games).
Mark the current page's segment selected: true. Tapping a segment
navigates to its href (or clicks the click selector), replacing
history so the back button doesn't walk back through segment switches.
297 298 299 300 301 302 303 |
# File 'lib/ruby_native/helper.rb', line 297 def segment(title, href: nil, click: nil, selected: false) data = { native_segment: "", native_title: title } data[:native_href] = href if href data[:native_click] = click if click data[:native_selected] = "" if selected add(@context.tag.div(data: data)) end |
#share_button(url: nil, title: "Share", icon: "square.and.arrow.up", icons: { android: "share" }, position: :trailing) ⇒ Object
Adds a native share button to the nav bar. Tapping it opens the
platform share sheet for url: (defaults to the current page on the
web side) so it works even where embedded web views don't support
navigator.share. Icons follow the same rules as the other navbar
buttons: icon: applies to every platform and icons: ({ ios:,
android: }) overrides per platform. Android defaults to the Material
share glyph; the SF Symbol default renders as missing there.
312 313 314 315 316 317 318 319 320 |
# File 'lib/ruby_native/helper.rb', line 312 def (url: nil, title: "Share", icon: "square.and.arrow.up", icons: { android: "share" }, position: :trailing) resolved = RubyNative::Helper.resolve_icon(icon: icon, icons: icons, platform: @context.try(:native_platform)) data = { native_button: "", native_share: "" } data[:native_title] = title if title data[:native_icon] = resolved if resolved data[:native_position] = position.to_s data[:native_share_url] = url if url add(@context.tag.div(data: data)) end |
#submit_button(title: "Save", click: "[type='submit']") ⇒ Object
322 323 324 325 326 327 328 |
# File 'lib/ruby_native/helper.rb', line 322 def (title: "Save", click: "[type='submit']") add(@context.tag.div(data: { native_submit_button: "", native_title: title, native_click: click })) end |
#to_html ⇒ Object
330 331 332 |
# File 'lib/ruby_native/helper.rb', line 330 def to_html @context.safe_join(@items) end |