Skip to content

Commit

Permalink
move f7VirtualList for consistency with Framework7 docs + add style…
Browse files Browse the repository at this point in the history
…s and mode
  • Loading branch information
hypebright committed Mar 22, 2024
1 parent 294e641 commit 47de7ab
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 185 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ the check icon position. Default to left.
- `f7CheckboxChoice()`: new function to pass inside `choices` in a
`f7CheckboxGroup()`. Improved choice with title, subtitle, ...
- `f7List()` has new `outline`, `dividers` and `strong` styles. `mode` gains 2 new values: `simple` and `links`.
- `f7Panel()` has new "floating"/"push" effets as well as a new `options` parameter
- `f7Panel()` has new "floating"/"push" effects as well as a new `options` parameter
to pass in extra configuration. See https://framework7.io/docs/panel#panel-parameters.
- `f7VirtualList()` has new `outline`, `dividers` and `strong` styles. Additionally, `mode` was added with the following possible values: `simple`, `links`, `media` or `contacts`.
- Fix various issues in documentation.

# shinyMobile 1.0.1
Expand Down
126 changes: 0 additions & 126 deletions R/f7List.R
Original file line number Diff line number Diff line change
Expand Up @@ -309,129 +309,3 @@ f7ListIndex <- function(id, target, ..., session = shiny::getDefaultReactiveDoma
message <- list(el = id, listEl = target, ...)
sendCustomMessage("listIndex", message, session)
}

#' Framework7 virtual list
#'
#' \code{f7VirtualList} is a high performance list container.
#' Use if you have too many components in \link{f7List}.
#'
#' @param id Virtual list unique id.
#' @param items List items. Slot for \link{f7VirtualListItem}.
#' @param rowsBefore Amount of rows (items) to be rendered before current
#' screen scroll position. By default it is equal to double amount of
#' rows (items) that fit to screen.
#' @param rowsAfter Amount of rows (items) to be rendered after current
#' screen scroll position. By default it is equal to the amount of rows
#' (items) that fit to screen.
#' @param cache Disable or enable DOM cache for already rendered list items.
#' In this case each item will be rendered only once and all further
#' manipulations will be with DOM element. It is useful if your list
#' items have some user interaction elements (like form elements or swipe outs)
#' or could be modified.
#'
#' @example inst/examples/virtualList/app.R
#'
#' @rdname virtuallist
#'
#' @export

f7VirtualList <- function(id, items, rowsBefore = NULL, rowsAfter = NULL,
cache = TRUE) {
config <- dropNulls(
list(
items = items,
rowsBefore = rowsBefore,
rowsAfter = rowsAfter,
cache = cache
)
)

shiny::tags$div(
id = id,
shiny::tags$script(
type = "application/json",
`data-for` = id,
jsonlite::toJSON(
x = config,
auto_unbox = TRUE,
json_verbatim = TRUE
)
),
class = "list virtual-list media-list searchbar-found"
)
}


#' Framework7 virtual list item
#'
#' \code{f7VirtualListItem} is an item component for \link{f7VirtualList}.
#'
#' @inheritParams f7ListItem
#' @rdname virtuallist
#' @export
f7VirtualListItem <- function(..., title = NULL, subtitle = NULL, header = NULL, footer = NULL,
href = NULL, media = NULL, right = NULL) {
dropNulls(
list(
content = ...,
title = title,
subtitle = subtitle,
header = header,
footer = footer,
url = href,
media = as.character(media), # avoid issue on JS side
right = right
)
)
}




#' Update an \link{f7VirtualList} on the server side
#'
#' This function wraps all methods from \url{https://framework7.io/docs/virtual-list.html}
#'
#' @param id \link{f7VirtualList} to update.
#' @param action Action to perform. See \url{https://framework7.io/docs/virtual-list.html}.
#' @param item If action is one of appendItem, prependItem, replaceItem, insertItemBefore.
#' @param items If action is one of appendItems, prependItems, replaceAllItems.
#' @param index If action is one of replaceItem, insertItemBefore, deleteItem.
#' @param indexes If action if one of filterItems, deleteItems.
#' @param oldIndex If action is moveItem.
#' @param newIndex If action is moveItem.
#' @param session Shiny session.
#'
#' @example inst/examples/virtualList/app.R
#'
#' @export

updateF7VirtualList <- function(id, action = c(
"appendItem", "appendItems", "prependItem",
"prependItems", "replaceItem", "replaceAllItems",
"moveItem", "insertItemBefore", "filterItems",
"deleteItem", "deleteAllItems", "scrollToItem"
),
item = NULL, items = NULL, index = NULL, indexes = NULL,
oldIndex = NULL, newIndex = NULL,
session = shiny::getDefaultReactiveDomain()) {
# JavaScript starts from 0!
index <- index - 1
indexes <- indexes - 1
oldIndex <- oldIndex - 1
newIndex <- newIndex - 1

message <- dropNulls(
list(
action = action,
item = item,
items = items,
index = index,
indexes = indexes,
oldIndex = oldIndex,
newIndex = newIndex
)
)

session$sendInputMessage(inputId = id, message)
}
139 changes: 139 additions & 0 deletions R/f7VirtualList.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#' Framework7 virtual list
#'
#' \code{f7VirtualList} is a high performance list container.
#' Use if you have too many components in \link{f7List}.
#'
#' @param id Virtual list unique id.
#' @param items List items. Slot for \link{f7VirtualListItem}.
#' @param rowsBefore Amount of rows (items) to be rendered before current
#' screen scroll position. By default it is equal to double amount of
#' rows (items) that fit to screen.
#' @param rowsAfter Amount of rows (items) to be rendered after current
#' screen scroll position. By default it is equal to the amount of rows
#' (items) that fit to screen.
#' @param cache Disable or enable DOM cache for already rendered list items.
#' In this case each item will be rendered only once and all further
#' manipulations will be with DOM element. It is useful if your list
#' items have some user interaction elements (like form elements or swipe outs)
#' or could be modified.
#' @param mode List mode. NULL, "simple", "links", "media" or "contacts".
#' @param inset Whether to display a card border. FALSE by default.
#' @param outline Outline style. Default to FALSE.
#' @param dividers Dividers style. Default to FALSE.
#' @param strong Strong style. Default to FALSE.
#'
#' @example inst/examples/virtualList/app.R
#'
#' @rdname virtuallist
#'
#' @export

f7VirtualList <- function(id, items, rowsBefore = NULL, rowsAfter = NULL,
cache = TRUE, mode = NULL, inset = FALSE, outline = FALSE,
dividers = FALSE, strong = FALSE) {

listCl <- "list virtual-list searchbar-found"
if (strong) listCl <- paste(listCl, "list-strong")
if (outline) listCl <- paste(listCl, "list-outline")
if (dividers) listCl <- paste(listCl, "list-dividers")
if (!is.null(mode)) listCl <- paste(listCl, sprintf("%s-list", mode))
if (inset) listCl <- paste(listCl, "inset")

config <- dropNulls(
list(
items = items,
rowsBefore = rowsBefore,
rowsAfter = rowsAfter,
cache = cache
)
)

shiny::tags$div(
id = id,
shiny::tags$script(
type = "application/json",
`data-for` = id,
jsonlite::toJSON(
x = config,
auto_unbox = TRUE,
json_verbatim = TRUE
)
),
class = listCl
)
}


#' Framework7 virtual list item
#'
#' \code{f7VirtualListItem} is an item component for \link{f7VirtualList}.
#'
#' @inheritParams f7ListItem
#' @rdname virtuallist
#' @export
f7VirtualListItem <- function(..., title = NULL, subtitle = NULL, header = NULL, footer = NULL,
href = NULL, media = NULL, right = NULL) {
dropNulls(
list(
content = ...,
title = title,
subtitle = subtitle,
header = header,
footer = footer,
url = href,
media = as.character(media), # avoid issue on JS side
right = right
)
)
}




#' Update an \link{f7VirtualList} on the server side
#'
#' This function wraps all methods from \url{https://framework7.io/docs/virtual-list.html}
#'
#' @param id \link{f7VirtualList} to update.
#' @param action Action to perform. See \url{https://framework7.io/docs/virtual-list.html}.
#' @param item If action is one of appendItem, prependItem, replaceItem, insertItemBefore.
#' @param items If action is one of appendItems, prependItems, replaceAllItems.
#' @param index If action is one of replaceItem, insertItemBefore, deleteItem.
#' @param indexes If action if one of filterItems, deleteItems.
#' @param oldIndex If action is moveItem.
#' @param newIndex If action is moveItem.
#' @param session Shiny session.
#'
#' @example inst/examples/virtualList/app.R
#'
#' @export

updateF7VirtualList <- function(id, action = c(
"appendItem", "appendItems", "prependItem",
"prependItems", "replaceItem", "replaceAllItems",
"moveItem", "insertItemBefore", "filterItems",
"deleteItem", "deleteAllItems", "scrollToItem"
),
item = NULL, items = NULL, index = NULL, indexes = NULL,
oldIndex = NULL, newIndex = NULL,
session = shiny::getDefaultReactiveDomain()) {
# JavaScript starts from 0!
index <- index - 1
indexes <- indexes - 1
oldIndex <- oldIndex - 1
newIndex <- newIndex - 1

message <- dropNulls(
list(
action = action,
item = item,
items = items,
index = index,
indexes = indexes,
oldIndex = oldIndex,
newIndex = newIndex
)
)

session$sendInputMessage(inputId = id, message)
}
13 changes: 5 additions & 8 deletions inst/examples/virtualList/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@ app <- shinyApp(
title = "Virtual List",
f7SingleLayout(
navbar = f7Navbar(
title = "Virtual Lists",
hairline = FALSE,
shadow = TRUE
title = "Virtual Lists"
),
# controls
f7Segment(
container = "segment",

f7Button(inputId = "appendItem", "Append Item"),
f7Button(inputId = "prependItems", "Prepend Items"),
f7Button(inputId = "insertBefore", "Insert before"),
f7Button(inputId = "replaceItem", "Replace Item")
),
f7Segment(
container = "segment",
f7Button(inputId = "deleteAllItems", "Remove All"),
f7Button(inputId = "moveItem", "Move Item"),
f7Button(inputId = "filterItems", "Filter Items")
Expand All @@ -37,15 +32,17 @@ app <- shinyApp(
id = "vlist",
rowsBefore = 2,
rowsAfter = 2,
mode = "media",
items = lapply(1:1000, function(i) {
f7VirtualListItem(
title = paste("Title", i),
subtitle = paste("Subtitle", i),
header = paste("Header", i),
footer = paste("Footer", i),
right = paste("Right", i),
content = i,
media = img(src = "https://cdn.framework7.io/placeholder/fashion-88x88-1.jpg")
content = paste0("Content", i),
media = img(style = "border-radius: 8px",
src = "https://cdn.framework7.io/placeholder/fashion-88x88-1.jpg")
)
})
)
Expand Down
4 changes: 2 additions & 2 deletions inst/shinyMobile-1.0.1/dist/shinyMobile.min.css.map

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions inst/shinyMobile-1.0.1/dist/shinyMobile.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions inst/shinyMobile-1.0.1/dist/shinyMobile.min.js.map

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions man/updateF7VirtualList.Rd

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

Loading

0 comments on commit 47de7ab

Please sign in to comment.