Skip to content

Commit 68513e9

Browse files
dskuzadskuza
andcommitted
fix(apple): force draw on offscreen settle / coming onscreen (#11840) 967973eca6
Co-authored-by: David Skuza <david@rive.app>
1 parent e80f00d commit 68513e9

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

.rive_head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e74f1cb12e4748bb1611b857d4413a9820dc9882
1+
967973eca66999f725d252a72dd59844c8589ca7

Source/RiveView.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ open class RiveView: RiveRendererView {
5959
/// if the artboard is unchanged.
6060
public var drawOptimization: DrawOptimization = .drawOnChanged
6161
private var forceDraw: Bool = false
62+
private var wasOnscreen: Bool = false
6263

6364
// MARK: Render Loop
6465
internal private(set) var isPlaying: Bool = false
@@ -421,7 +422,14 @@ open class RiveView: RiveRendererView {
421422

422423
RiveLogger.log(view: self, event: .advance(delta))
423424
playerDelegate?.player(didAdvanceby: delta, riveModel: riveModel)
424-
425+
426+
// If the animation stopped playing, but we are offscreen,
427+
// force a draw so that the animation is in the correct state
428+
// when it appears onscreen again
429+
if (isPlaying == false && isOnscreen() == false) {
430+
forceDraw = true
431+
}
432+
425433
// Trigger a redraw
426434
needsDisplay()
427435
}
@@ -451,8 +459,17 @@ open class RiveView: RiveRendererView {
451459
}
452460

453461
open override func draw(_ rect: CGRect) {
462+
let isOnscreen = isOnscreen()
463+
// If we were previously offscreen and we just moved onscreen
464+
// make sure we force a draw. In the case where a data binding
465+
// property, for example, was set while offscreen, this will
466+
// force the view to draw the latest state.
467+
if wasOnscreen == false && isOnscreen {
468+
forceDraw = true
469+
}
470+
454471
// First check whether we should draw and we're on-screen
455-
if offscreenBehavior == .playAndDraw || isOnscreen() {
472+
if offscreenBehavior == .playAndDraw || isOnscreen || forceDraw {
456473
// Then check our optimization. Draw if:
457474
// 1. We always draw, or
458475
// 2. If we don't, if the artboard changed
@@ -464,6 +481,7 @@ open class RiveView: RiveRendererView {
464481
super.draw(rect)
465482
forceDraw = false
466483
}
484+
wasOnscreen = isOnscreen
467485
}
468486

469487
open override func drawableSizeDidChange(_ drawableSize: CGSize) {

0 commit comments

Comments
 (0)