Skip to content

Commit

Permalink
update actionSheet test + fix issue with updateActionSheet within mod…
Browse files Browse the repository at this point in the history
…ule (missing namespace)
  • Loading branch information
DivadNojnarg committed Mar 15, 2024
1 parent 0748fda commit b6a5826
Show file tree
Hide file tree
Showing 19 changed files with 273 additions and 433 deletions.
216 changes: 4 additions & 212 deletions R/f7ActionSheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,153 +31,11 @@
#'
#' @export
#'
#' @examples
#' if (interactive()) {
#' library(shiny)
#' library(shinyMobile)
#'
#' shinyApp(
#' ui = f7Page(
#' title = "Action sheet",
#' f7SingleLayout(
#' navbar = f7Navbar("Action sheet"),
#' br(),
#' f7Button(inputId = "go", label = "Show action sheet", color = "red")
#' )
#' ),
#' server = function(input, output, session) {
#'
#' observe({
#' print(list(
#' sheetOpen = input$action1,
#' button = input$action1_button
#' ))
#' })
#'
#' observeEvent(input$action1_button, {
#' if (input$action1_button == 1) {
#' f7Notif(
#' text = "You clicked on the first button",
#' icon = f7Icon("bolt_fill"),
#' title = "Notification",
#' titleRightText = "now"
#' )
#' } else if (input$action1_button == 2) {
#' f7Dialog(
#' id = "test",
#' title = "Click me to launch a Toast!",
#' type = "confirm",
#' text = "You clicked on the second button"
#' )
#' }
#' })
#'
#' observeEvent(input$test, {
#' f7Toast(text = paste("Alert input is:", input$test))
#' })
#'
#' observeEvent(input$go, {
#' f7ActionSheet(
#' grid = TRUE,
#' id = "action1",
#' buttons = list(
#' list(
#' text = "Notification",
#' icon = f7Icon("info"),
#' color = NULL
#' ),
#' list(
#' text = "Dialog",
#' icon = f7Icon("lightbulb_fill"),
#' color = NULL
#' )
#' )
#' )
#' })
#' }
#' )
#'
#' ### in shiny module
#' library(shiny)
#' library(shinyMobile)
#'
#' sheetModuleUI <- function(id) {
#' ns <- NS(id)
#' f7Button(inputId = ns("go"), label = "Show action sheet", color = "red")
#' }
#'
#' sheetModule <- function(input, output, session) {
#'
#' ns <- session$ns
#'
#' observe({
#' print(list(
#' sheetOpen = input$action1,
#' button = input$action1_button
#' ))
#' })
#'
#' observeEvent(input$action1_button, {
#' if (input$action1_button == 1) {
#' f7Notif(
#' text = "You clicked on the first button",
#' icon = f7Icon("bolt_fill"),
#' title = "Notification",
#' titleRightText = "now"
#' )
#' } else if (input$action1_button == 2) {
#' f7Dialog(
#' id = ns("test"),
#' title = "Click me to launch a Toast!",
#' type = "confirm",
#' text = "You clicked on the second button",
#' )
#' }
#' })
#'
#' observeEvent(input$test, {
#' f7Toast(text = paste("Alert input is:", input$test))
#' })
#'
#' observeEvent(input$go, {
#' f7ActionSheet(
#' grid = TRUE,
#' id = ns("action1"),
#' buttons = list(
#' list(
#' text = "Notification",
#' icon = f7Icon("info"),
#' color = NULL
#' ),
#' list(
#' text = "Dialog",
#' icon = f7Icon("lightbulb_fill"),
#' color = NULL
#' )
#' )
#' )
#' })
#' }
#'
#' shinyApp(
#' ui = f7Page(
#' title = "Action sheet",
#' f7SingleLayout(
#' navbar = f7Navbar("Action sheet"),
#' br(),
#' sheetModuleUI(id = "sheet1")
#' )
#' ),
#' server = function(input, output, session) {
#' callModule(sheetModule, "sheet1")
#' }
#' )
#' }
#' @example inst/examples/actionsheet/app.R
f7ActionSheet <- function(id, buttons, grid = FALSE, ..., session = shiny::getDefaultReactiveDomain()) {

buttons <- lapply(buttons, dropNulls)

for(i in seq_along(buttons)) {
for (i in seq_along(buttons)) {
temp <- as.character(buttons[[i]]$icon)
buttons[[i]]$icon <- temp
}
Expand All @@ -192,8 +50,6 @@ f7ActionSheet <- function(id, buttons, grid = FALSE, ..., session = shiny::getDe
sendCustomMessage("action-sheet", message, session)
}



#' Update Framework7 action sheet
#'
#' \code{updateF7ActionSheet} updates an \link{f7ActionSheet} from the server.
Expand All @@ -205,80 +61,16 @@ f7ActionSheet <- function(id, buttons, grid = FALSE, ..., session = shiny::getDe
#' @param session Shiny session object.
#' @rdname actionsheet
#' @export
#' @examples
#' if (interactive()) {
#' library(shiny)
#' library(shinyMobile)
#'
#' shinyApp(
#' ui = f7Page(
#' title = "Update Action sheet",
#' f7SingleLayout(
#' navbar = f7Navbar("Update Action sheet"),
#' br(),
#' f7Segment(
#' f7Button(inputId = "go", label = "Show action sheet", color = "green"),
#' f7Button(inputId = "update", label = "Update action sheet", color = "red")
#' )
#' )
#' ),
#' server = function(input, output, session) {
#'
#' observe({
#' print(list(
#' sheetOpen = input$action1,
#' button = input$action1_button
#' ))
#' })
#'
#' observeEvent(input$go, {
#' f7ActionSheet(
#' grid = TRUE,
#' id = "action1",
#' buttons = list(
#' list(
#' text = "Notification",
#' icon = f7Icon("info"),
#' color = NULL
#' ),
#' list(
#' text = "Dialog",
#' icon = f7Icon("lightbulb_fill"),
#' color = NULL
#' )
#' )
#' )
#' })
#'
#' observeEvent(input$update, {
#' updateF7ActionSheet(
#' id = "action1",
#' options = list(
#' grid = TRUE,
#' buttons = list(
#' list(
#' text = "Plop",
#' icon = f7Icon("info"),
#' color = "orange"
#' )
#' )
#' )
#' )
#' })
#' }
#' )
#' }
updateF7ActionSheet <- function(id, options, session = shiny::getDefaultReactiveDomain()) {

# Convert shiny tags to character
if (length(options$buttons) > 0) {
for(i in seq_along(options$buttons)) {
for (i in seq_along(options$buttons)) {
temp <- as.character(options$buttons[[i]]$icon)
options$buttons[[i]]$icon <- temp
}
}

options$id <- id
options$id <- session$ns(id)

sendCustomMessage("update-action-sheet", options, session)
}
92 changes: 92 additions & 0 deletions inst/examples/actionsheet/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
library(shiny)
library(shinyMobile)

sheetModuleUI <- function(id) {
ns <- NS(id)
f7Segment(
f7Button(inputId = ns("go"), label = "Show action sheet", color = "green"),
f7Button(inputId = ns("update"), label = "Update action sheet", color = "red")
)
}

sheetModule <- function(id) {
moduleServer(
id,
function(input, output, session) {
ns <- session$ns

observeEvent(input$action1_button, {
if (input$action1_button == 1) {
f7Notif(
text = "You clicked on the first button",
icon = f7Icon("bolt_fill"),
title = "Notification",
titleRightText = "now"
)
} else if (input$action1_button == 2) {
f7Dialog(
id = ns("test"),
title = "Click me to launch a Toast!",
type = "confirm",
text = "You clicked on the second button",
)
}
})

observeEvent(input$test, {
f7Toast(text = paste("Alert input is:", input$test))
})

observeEvent(input$go, {
f7ActionSheet(
grid = TRUE,
id = ns("action1"),
buttons = list(
list(
text = "Notification",
icon = f7Icon("info"),
color = NULL
),
list(
text = "Dialog",
icon = f7Icon("lightbulb_fill"),
color = NULL
)
)
)
})

observeEvent(input$update, {
updateF7ActionSheet(
id = "action1",
options = list(
grid = TRUE,
buttons = list(
list(
text = "Plop",
icon = f7Icon("info"),
color = "orange"
)
)
)
)
})
}
)
}

app <- shinyApp(
ui = f7Page(
title = "Action sheet",
f7SingleLayout(
navbar = f7Navbar("Action sheet"),
br(),
sheetModuleUI(id = "sheet1")
)
),
server = function(input, output, session) {
sheetModule("sheet1")
}
)

if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app
2 changes: 1 addition & 1 deletion inst/shinyMobile-1.0.1/dist/shinyMobile.min.css.map

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions inst/shinyMobile-1.0.1/dist/shinyMobile.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions inst/shinyMobile-1.0.1/dist/shinyMobile.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit b6a5826

Please sign in to comment.