Skip to content

Commit

Permalink
start update f7Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Mar 14, 2024
1 parent 41e926e commit 69274e0
Show file tree
Hide file tree
Showing 31 changed files with 297 additions and 288 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export(create_manifest)
export(f7Accordion)
export(f7AccordionItem)
export(f7ActionSheet)
export(f7AddMessages)
export(f7Align)
export(f7Appbar)
export(f7AutoComplete)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
- The aurora theme has been removed. Supported themes are now: ios, md and auto. In case of auto it will use iOS theme for iOS devices and MD theme for all other devices.
- `f7Accordion()`:
- `multiCollapse` has been removed in Framework7.
- `f7AddMessages()` is definitely removed. Deprecated from other releases.

## Minor change
- `f7Messages()`: the corresponding input is now a list of lists, each item
being a single `f7Message()`. The previous setting was not optimal R,the JS binding was returning a array of objects, which can't be easily translated to R.
We now return an object of objects which becomes a list of lists.

# shinyMobile 1.0.1

Expand Down
194 changes: 51 additions & 143 deletions R/f7Messages.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,72 +15,9 @@
#'
#' @rdname messages
#' @export
#' @examples
#' if (interactive()) {
#' library(shiny)
#' library(shinyMobile)
#' shinyApp(
#' ui = f7Page(
#' title = "Messages",
#' f7SingleLayout(
#' navbar = f7Navbar(
#' title = "Messages",
#' hairline = FALSE,
#' shadow = TRUE
#' ),
#' toolbar = f7MessageBar(inputId = "mymessagebar", placeholder = "Message"),
#' # main content
#' f7Messages(id = "mymessages", title = "My message")
#'
#' )
#' ),
#' server = function(input, output, session) {
#' observe({
#' print(input[["mymessagebar-send"]])
#' print(input$mymessages)
#' })
#' observeEvent(input[["mymessagebar-send"]], {
#' updateF7Messages(
#' id = "mymessages",
#' list(
#' f7Message(
#' text = input$mymessagebar,
#' name = "David",
#' type = "sent",
#' header = "Message Header",
#' footer = "Message Footer",
#' textHeader = "Text Header",
#' textFooter = "text Footer",
#' avatar = "https://cdn.framework7.io/placeholder/people-100x100-7.jpg"
#' )
#' )
#' )
#' })
#'
#' observe({
#' invalidateLater(5000)
#' names <- c("Victor", "John")
#' name <- sample(names, 1)
#'
#' updateF7Messages(
#' id = "mymessages",
#' list(
#' f7Message(
#' text = "Some message",
#' name = name,
#' type = "received",
#' avatar = "https://cdn.framework7.io/placeholder/people-100x100-9.jpg"
#' )
#' )
#' )
#' })
#'
#' }
#' )
#' }
#' @example inst/examples/messages/app.R
f7Messages <- function(id, title = NULL, autoLayout = TRUE, newMessagesFirst = FALSE,
scrollMessages = TRUE, scrollMessagesOnEdge = TRUE) {

config <- dropNulls(
list(
autoLayout = autoLayout,
Expand All @@ -106,7 +43,6 @@ f7Messages <- function(id, title = NULL, autoLayout = TRUE, newMessagesFirst = F
shiny::tags$div(class = "messages-title", title)
}
)

}


Expand All @@ -122,13 +58,12 @@ f7Messages <- function(id, title = NULL, autoLayout = TRUE, newMessagesFirst = F
#' @rdname messagebar
#' @export
f7MessageBar <- function(inputId, placeholder = "Message") {

ns <- shiny::NS(inputId)

shiny::tags$div(
id = inputId,
# add this to be able to see the message bar in a f7TabLayout...
#style = "margin-bottom: 100px;",
# style = "margin-bottom: 100px;",
class = "toolbar messagebar",
shiny::tags$div(
class = "toolbar-inner",
Expand Down Expand Up @@ -165,57 +100,56 @@ f7MessageBar <- function(inputId, placeholder = "Message") {
#' @export
#' @examples
#' if (interactive()) {
#' library(shiny)
#' library(shinyMobile)
#' shinyApp(
#' ui = f7Page(
#' title = "Update message bar",
#' f7SingleLayout(
#' navbar = f7Navbar(
#' title = "Message bar",
#' hairline = FALSE,
#' shadow = TRUE
#' ),
#' toolbar = f7Toolbar(
#' position = "bottom",
#' f7Link(label = "Link 1", href = "https://www.google.com"),
#' f7Link(label = "Link 2", href = "https://www.google.com")
#' ),
#' # main content
#' f7Segment(
#' container = "segment",
#' f7Button("updateMessageBar", "Update value"),
#' f7Button("updateMessageBarPlaceholder", "Update placeholder")
#' ),
#' f7MessageBar(inputId = "mymessagebar", placeholder = "Message"),
#' uiOutput("messageContent")
#' )
#' ),
#' server = function(input, output, session) {
#'
#' output$messageContent <- renderUI({
#' req(input$mymessagebar)
#' tagList(
#' f7BlockTitle("Message Content", size = "large"),
#' f7Block(strong = TRUE, inset = TRUE, input$mymessagebar)
#' library(shiny)
#' library(shinyMobile)
#' shinyApp(
#' ui = f7Page(
#' title = "Update message bar",
#' f7SingleLayout(
#' navbar = f7Navbar(
#' title = "Message bar",
#' hairline = FALSE,
#' shadow = TRUE
#' ),
#' toolbar = f7Toolbar(
#' position = "bottom",
#' f7Link(label = "Link 1", href = "https://www.google.com"),
#' f7Link(label = "Link 2", href = "https://www.google.com")
#' ),
#' # main content
#' f7Segment(
#' container = "segment",
#' f7Button("updateMessageBar", "Update value"),
#' f7Button("updateMessageBarPlaceholder", "Update placeholder")
#' ),
#' f7MessageBar(inputId = "mymessagebar", placeholder = "Message"),
#' uiOutput("messageContent")
#' )
#' })
#' ),
#' server = function(input, output, session) {
#' output$messageContent <- renderUI({
#' req(input$mymessagebar)
#' tagList(
#' f7BlockTitle("Message Content", size = "large"),
#' f7Block(strong = TRUE, inset = TRUE, input$mymessagebar)
#' )
#' })
#'
#' observeEvent(input$updateMessageBar, {
#' updateF7MessageBar(
#' inputId = "mymessagebar",
#' value = "sjsjsj"
#' )
#' })
#' observeEvent(input$updateMessageBar, {
#' updateF7MessageBar(
#' inputId = "mymessagebar",
#' value = "sjsjsj"
#' )
#' })
#'
#' observeEvent(input$updateMessageBarPlaceholder, {
#' updateF7MessageBar(
#' inputId = "mymessagebar",
#' placeholder = "Enter your message"
#' )
#' })
#' }
#' )
#' observeEvent(input$updateMessageBarPlaceholder, {
#' updateF7MessageBar(
#' inputId = "mymessagebar",
#' placeholder = "Enter your message"
#' )
#' })
#' }
#' )
#' }
updateF7MessageBar <- function(inputId, value = NULL, placeholder = NULL,
session = shiny::getDefaultReactiveDomain()) {
Expand Down Expand Up @@ -255,7 +189,6 @@ f7Message <- function(text, name, type = c("sent", "received"),
header = NULL, footer = NULL, avatar = NULL,
textHeader = NULL, textFooter = NULL, image = NULL,
imageSrc = NULL, cssClass = NULL) {

type <- match.arg(type)
dropNulls(
list(
Expand All @@ -267,7 +200,7 @@ f7Message <- function(text, name, type = c("sent", "received"),
type = type,
textHeader = textHeader,
textFooter = textFooter,
image = image,
image = image,
imageSrc = imageSrc
)
)
Expand All @@ -289,9 +222,7 @@ f7Message <- function(text, name, type = c("sent", "received"),
#' @rdname messages
#' @export
updateF7Messages <- function(id, messages, showTyping = FALSE,
session = shiny::getDefaultReactiveDomain()) {


session = shiny::getDefaultReactiveDomain()) {
message <- list(
value = jsonlite::toJSON(
messages,
Expand All @@ -304,26 +235,3 @@ updateF7Messages <- function(id, messages, showTyping = FALSE,

session$sendInputMessage(id, message)
}


#' Update Framework7 message container
#'
#' \code{f7AddMessages} adds messages to an \link{f7Messages} container.
#' Use \link{updateF7Messages} instead
#'
#' @rdname f7-deprecated
#' @inheritParams updateF7Messages
#' @keywords internal
#' @export
f7AddMessages <- function(id, messages, showTyping = FALSE,
session = shiny::getDefaultReactiveDomain()) {

.Deprecated(
"updateF7Messages",
package = "shinyMobile",
"f7AddMessages will be removed in future release. Please use
updateF7Messages instead.",
old = as.character(sys.call(sys.parent()))[1L]
)
updateF7Messages(id, messages, showTyping, session)
}
59 changes: 59 additions & 0 deletions inst/examples/messages/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
library(shiny)
library(shinyMobile)

app <- shinyApp(
ui = f7Page(
title = "Messages",
f7SingleLayout(
navbar = f7Navbar(
title = "Messages",
hairline = FALSE,
shadow = TRUE
),
toolbar = f7MessageBar(inputId = "mymessagebar", placeholder = "Message"),
# main content
f7Messages(id = "mymessages", title = "My message")
)
),
server = function(input, output, session) {
observe({
print(input$mymessages)
})
# Send a message
observeEvent(input[["mymessagebar-send"]], {
updateF7Messages(
id = "mymessages",
list(
f7Message(
text = input$mymessagebar,
name = "David",
type = "sent",
header = "Message Header",
footer = "Message Footer",
textHeader = "Text Header",
textFooter = "text Footer",
avatar = "https://cdn.framework7.io/placeholder/people-100x100-7.jpg"
)
)
)
})

# Receive a message
observeEvent(TRUE, {
updateF7Messages(
id = "mymessages",
showTyping = FALSE, # DOES NOT WORK YET WHEN TRUE ...
list(
f7Message(
text = "Some message",
name = "Victor",
type = "received",
avatar = "https://cdn.framework7.io/placeholder/people-100x100-9.jpg"
)
)
)
})
}
)

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

Large diffs are not rendered by default.

18 changes: 9 additions & 9 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.

20 changes: 2 additions & 18 deletions man/f7-deprecated.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 69274e0

Please sign in to comment.