Skip to content

Commit

Permalink
testing message bar, refactore input bindings + doc tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Mar 15, 2024
1 parent 7841499 commit 0748fda
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 185 deletions.
70 changes: 3 additions & 67 deletions R/f7Messages.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ f7Messages <- function(id, title = NULL, autoLayout = TRUE, newMessagesFirst = F
)
}




#' Framework7 message bar.
#'
#' \code{f7MessageBar} creates a message text container to type new messages.
Expand Down Expand Up @@ -84,9 +81,6 @@ f7MessageBar <- function(inputId, placeholder = "Message") {
)
}




#' Update Framework7 message bar
#'
#' \code{updateF7MessageBar} updates message bar content on the server side.
Expand All @@ -98,59 +92,7 @@ f7MessageBar <- function(inputId, placeholder = "Message") {
#'
#' @rdname messagebar
#' @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)
#' )
#' })
#'
#' observeEvent(input$updateMessageBar, {
#' updateF7MessageBar(
#' inputId = "mymessagebar",
#' value = "sjsjsj"
#' )
#' })
#'
#' observeEvent(input$updateMessageBarPlaceholder, {
#' updateF7MessageBar(
#' inputId = "mymessagebar",
#' placeholder = "Enter your message"
#' )
#' })
#' }
#' )
#' }
#' @example inst/examples/messagebar/app.R
updateF7MessageBar <- function(inputId, value = NULL, placeholder = NULL,
session = shiny::getDefaultReactiveDomain()) {
message <- dropNulls(
Expand All @@ -163,10 +105,6 @@ updateF7MessageBar <- function(inputId, value = NULL, placeholder = NULL,
session$sendInputMessage(inputId, message)
}





#' Framework7 message element
#'
#' \code{f7Message} creates a message item to be inserted in
Expand Down Expand Up @@ -206,16 +144,14 @@ f7Message <- function(text, name, type = c("sent", "received"),
)
}



#' Update Framework7 message container
#'
#' \code{updateF7Messages} add messages to an \link{f7Messages} container.
#' \code{updateF7Messages} add messages to a \link{f7Messages} container.
#'
#' @param id Reference to \link{f7Messages} container.
#' @param showTyping Show typing when a new message comes. Default to FALSE.
#' Does not work yet...
#' @param messages List of \link{f7Messages}.
#' @param messages List of \link{f7Message}.
#' @param session Shiny session object
#'
#'
Expand Down
51 changes: 51 additions & 0 deletions inst/examples/messagebar/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
library(shiny)
library(shinyMobile)

app <- 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$updateMessageBarPlaceholder, {
updateF7MessageBar(
inputId = "mymessagebar",
placeholder = "Enter your message"
)
})
}
)

if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app
3 changes: 0 additions & 3 deletions inst/examples/messages/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ app <- shinyApp(
)
),
server = function(input, output, session) {
observe({
print(input$mymessages)
})
# Send a message
observeEvent(input[["mymessagebar-send"]], {
updateF7Messages(
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyMobile-1.0.1/dist/shinyMobile.min.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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.

99 changes: 49 additions & 50 deletions man/messagebar.Rd

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

7 changes: 2 additions & 5 deletions man/messages.Rd

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

11 changes: 6 additions & 5 deletions srcjs/bindings/messageBarInputBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $.extend(f7MessageBarBinding, {

initialize: function(el) {
this.app = getAppInstance();
this.app.messagebar.create({
this.instance = this.app.messagebar.create({
el: '#' + $(el).attr('id')
});
},
Expand All @@ -17,7 +17,7 @@ $.extend(f7MessageBarBinding, {
// send button based on the current value.
// It also returns the text area value
setState: function(el) {
var val = this.app.messagebar.get(el).getValue();
var val = this.instance.getValue();
var sendLink = $(el).find('#' + el.id + '-send');
if (!val.length) {
$(sendLink).addClass('disabled');
Expand All @@ -38,11 +38,11 @@ $.extend(f7MessageBarBinding, {

// see updatef7MessageBar
setValue: function(el, value) {
this.app.messagebar.get(el).setValue(value);
this.instance.setValue(value);
},

setPlaceholder: function(el, value) {
this.app.messagebar.get(el).setPlaceholder(value);
this.instance.setPlaceholder(value);
},

// see updatef7MessageBar
Expand All @@ -57,14 +57,15 @@ $.extend(f7MessageBarBinding, {
},

subscribe: function(el, callback) {
var self = this;
$(el).on("input.f7MessageBarBinding change.f7MessageBarBinding focus.f7MessageBarBinding blur.f7MessageBarBinding", function(e) {
// reset message bar textarea content when click on it
$(el).find('#' + el.id + '-send').on('click', function() {
// add delay between link click and textarea reset in f7MessageBar.
// Needed to give time so that f7Messages receives
// the textarea input value before it is cleared.
setTimeout(function() {
this.app.messagebar.get(el).clear().focus();
self.instance.clear().focus();
}, 1000);
});
callback(true);
Expand Down
Loading

0 comments on commit 0748fda

Please sign in to comment.