MCPcopy Create free account
hub / github.com/Snapchat/Valdi / measure

Method measure

valdi/src/valdi/runtime/Views/PlaceholderViewMeasureDelegate.cpp:19–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17PlaceholderViewMeasureDelegate::~PlaceholderViewMeasureDelegate() = default;
18
19Size PlaceholderViewMeasureDelegate::measure(
20 ViewNode& viewNode, float width, MeasureMode widthMode, float height, MeasureMode heightMode) {
21 auto* viewNodeTree = viewNode.getViewNodeTree();
22 auto currentViewTransactionScope = viewNodeTree->getCurrentViewTransactionScopeRef();
23 auto& transaction = currentViewTransactionScope->transaction();
24
25 currentViewTransactionScope->flushNow(/* sync */ true);
26
27 Size measuredSize;
28 transaction.executeInTransactionThread([&]() {
29 // We set a nested direct view transaction scope during the measure pass, so that all operations that
30 // occur are direct.
31 auto nestedViewTransactionScope = makeShared<ViewTransactionScope>(
32 viewNodeTree->getViewManager(), currentViewTransactionScope->getMainThreadManager(), false);
33 viewNodeTree->unsafeSetCurrentViewTransactionScope(nestedViewTransactionScope);
34
35 if (viewNode.getView() != nullptr) {
36 measuredSize = measureView(viewNode.getView(), width, widthMode, height, heightMode);
37 } else {
38 std::lock_guard<Mutex> guard(_mutex);
39 if (!_didFetchPlaceholderView) {
40 _didFetchPlaceholderView = true;
41 _placeholderView = createPlaceholderView();
42 }
43
44 if (_placeholderView == nullptr) {
45 measuredSize = Size();
46 return;
47 }
48
49 auto placeholderViewNode = viewNode.makePlaceholderViewNode(*nestedViewTransactionScope, _placeholderView);
50
51 nestedViewTransactionScope->flushNow(/* sync */ true);
52
53 measuredSize = measureView(_placeholderView, width, widthMode, height, heightMode);
54
55 nestedViewTransactionScope->transaction().moveViewToTree(_placeholderView, viewNodeTree, nullptr);
56 placeholderViewNode->removeView(*nestedViewTransactionScope);
57 nestedViewTransactionScope->submit();
58 }
59 });
60
61 currentViewTransactionScope->flushNow(/* sync */ true);
62 // Set the view transaction back to what it was before measuring
63 viewNodeTree->unsafeSetCurrentViewTransactionScope(currentViewTransactionScope);
64
65 return measuredSize;
66}
67
68} // namespace Valdi

Callers

nothing calls this directly

Calls 12

getViewNodeTreeMethod · 0.80
flushNowMethod · 0.80
getViewManagerMethod · 0.80
removeViewMethod · 0.80
SizeClass · 0.70
getMainThreadManagerMethod · 0.45
getViewMethod · 0.45
moveViewToTreeMethod · 0.45
submitMethod · 0.45

Tested by

no test coverage detected