Store and Load the View State
The view state is the data we capture, store, and eventually use to restore what the user is currently looking at after recreating a
PdfView — for example, after suspending and restoring your app.
This guide aims to provide an explanation of the concepts behind the view state and how it is used inside PSPDFKit.
What’s in the ViewState
ViewState class is convenient for examining the entire current view state. This class can be used via the relevant JSON methods to persist the state. In order to restore
ViewState properties, there are corresponding asynchronous methods provided by the UI
Controller for the individual properties, or you can set them all at once with
CurrentPageIndex is the currently visible dominant page. Just like the page index returned by
Controller.GetCurrentPageIndexAsync, the view state’s page index that relates to the first page in a document is
0. To restore the current page, use the method
LayoutMode describes how pages inside a view are displayed, e.g. a value of
Double means pages will always be displayed in groups of two.
ZoomMode describes the current zoom factor, e.g. a value of
FitToViewPort means the view will fit the current page into the viewport completely.
ScrollMode describes the mode of page scrolling in the viewport — either continuous or per spread (paginated).
InteractionMode describes the current interaction mode, e.g. a value of
Pan means the pan tool is active and allows the user to navigate using mouse dragging or touch dragging. A value of
Text means a text edit box is currently active and taking input from a keyboard. A value of
None means no interaction mode is currently active. There are several interaction modes, but these are just three examples.