Skip to content

Commit

Permalink
add fadeOut arg to stop method
Browse files Browse the repository at this point in the history
  • Loading branch information
hypebright committed Mar 4, 2024
1 parent 766e419 commit 9e55a61
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 14 deletions.
9 changes: 6 additions & 3 deletions R/fireworks.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ Fireworks <- R6::R6Class(
},
#' @details
#' Stop the fireworks
stop = function(){
#' @param fadeOut Whether to fade out the fireworks before stopping. Note that
#' this will take 2000ms to complete.
stop = function(fadeOut = FALSE){
if (is.null(private$.id)) {
private$.session$sendCustomMessage("fireworks-stop", list())
private$.session$sendCustomMessage("fireworks-stop", list(fadeOut = fadeOut))
} else {
for (i in 1:length(private$.id)) {
private$.session$sendCustomMessage("fireworks-stop", list(id = private$.id[[i]]))
private$.session$sendCustomMessage("fireworks-stop", list(id = private$.id[[i]],
fadeOut = fadeOut))
}
}
invisible(self)
Expand Down
2 changes: 1 addition & 1 deletion inst/examples/02-fireworks-on-demand.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ server <- function(input, output, session) {
}) |> bindEvent(input$launch)

observe({
fw$stop()
fw$stop(fadeOut = TRUE)
}) |> bindEvent(input$stop)

}
Expand Down
2 changes: 1 addition & 1 deletion inst/fireworks-0.1.0/dist/fireworks.min.css.map

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

2 changes: 1 addition & 1 deletion inst/fireworks-0.1.0/dist/fireworks.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions inst/fireworks-0.1.0/dist/fireworks.min.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion man/fireworksClass.Rd

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

26 changes: 22 additions & 4 deletions srcjs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,28 @@ Shiny.addCustomMessageHandler("fireworks-start", function(message) {

Shiny.addCustomMessageHandler("fireworks-stop", function(message) {
const identifier = message.id == null ? "full-screen" : message.id;
window[`fireworks-${identifier}`].stop();

if (message.id == null) {
document.body.removeChild(document.querySelector(".fireworks-full-screen"));
const currentOpts = window[`fireworks-${identifier}`].currentOptions;

const stopFireworks = () => {
window[`fireworks-${identifier}`].stop();
if (message.id == null) {
document.body.removeChild(
document.querySelector(".fireworks-full-screen")
);
}
};

if (message.fadeOut) {
window[`fireworks-${identifier}`].updateOptions({
...currentOpts,
intensity: 1
});
// add 2000 ms delay to allow fireworks to fade out
setTimeout(() => {
stopFireworks();
}, 2000);
} else {
stopFireworks();
}
});

0 comments on commit 9e55a61

Please sign in to comment.