Skip to content

Commit ea7277b

Browse files
philterphilter
andcommitted
chore: Add more Stateful Component tests (#12438) 13be041786
Adds several more real world tests for Stateful Components. Tests also uncovered 2 bugs which are fixed in this PR. - Fixes cross file copy/pasting stateful artboards to make sure any VM instances that are copied are correctly reparented when pasted. - We missed the VM artboard property bound to NestedArtboard's artboard case. Fixed, so now we always setup/cleanup new stateful VM instances when artboards are swapped via databinding. Co-authored-by: Philip Chung <philterdesign@gmail.com>
1 parent 5d1ae16 commit ea7277b

12 files changed

Lines changed: 667 additions & 2 deletions

.rive_head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ee268b5467f8f4bf67ad634d31a5b8e3e9ff6c71
1+
13be041786e7811cffc3d5a7a474357619625536

src/nested_artboard.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void NestedArtboard::updateArtboard(
139139
m_referencedArtboard = nullptr;
140140
}
141141
m_Instance = nullptr;
142+
m_statefulViewModelInstance = nullptr;
142143
return;
143144
}
144145

@@ -159,6 +160,33 @@ void NestedArtboard::updateArtboard(
159160
nestedStateMachine)); // take ownership
160161
}
161162
referencedArtboard(artboardInstance.release());
163+
164+
if (artboard->isStateful())
165+
{
166+
const bool cacheStale =
167+
m_statefulViewModelInstance == nullptr ||
168+
m_statefulViewModelInstance->viewModelId() !=
169+
artboard->viewModelId();
170+
if (cacheStale)
171+
{
172+
auto vm = m_file != nullptr
173+
? m_file->viewModel(artboard->viewModelId())
174+
: nullptr;
175+
m_statefulViewModelInstance =
176+
vm != nullptr ? m_file->createDefaultViewModelInstance(vm)
177+
: nullptr;
178+
if (m_statefulViewModelInstance != nullptr)
179+
{
180+
m_file->completeViewModelProperties(
181+
m_statefulViewModelInstance.get());
182+
}
183+
}
184+
}
185+
else
186+
{
187+
m_statefulViewModelInstance = nullptr;
188+
}
189+
162190
if (viewModelInstanceArtboard->boundViewModelInstance())
163191
{
164192
bindViewModelInstance(
858 KB
Binary file not shown.
858 KB
Binary file not shown.
858 KB
Binary file not shown.
858 KB
Binary file not shown.

0 commit comments

Comments
 (0)