Skip to content

Commit 812f659

Browse files
committed
fix: faster initial layout via measure guessing
1 parent af4e5dd commit 812f659

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

cpp/PdfViewState.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@
22

33
namespace facebook::react {
44

5-
PdfViewState::PdfViewState() : width(1), height(1) {}
5+
namespace {
6+
// Heuristic: guess that new pages will be the same dimensions as the last
7+
// measured page.
8+
int defaultWidth = 1;
9+
int defaultHeight = 1;
10+
} // namespace
611

7-
PdfViewState::PdfViewState(int _width, int _height) : width(_width), height(_height) {}
12+
PdfViewState::PdfViewState() : width(defaultWidth), height(defaultHeight) {}
13+
14+
PdfViewState::PdfViewState(int _width, int _height) : width(_width), height(_height) {
15+
defaultWidth = width;
16+
defaultHeight = height;
17+
}
818

919
#ifdef RN_SERIALIZABLE_STATE
1020
PdfViewState::PdfViewState(const PdfViewState& previousState, folly::dynamic data)
11-
: width(data["width"].getInt()), height(data["height"].getInt()) {}
21+
: width(data["width"].getInt()), height(data["height"].getInt()) {
22+
defaultWidth = width;
23+
defaultHeight = height;
24+
}
1225

1326
folly::dynamic PdfViewState::getDynamic() const {
1427
return folly::dynamic::object("width", width)("height", height);

0 commit comments

Comments
 (0)