ScrollViewState.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #pragma once
  8. #include <react/graphics/Geometry.h>
  9. #include <folly/dynamic.h>
  10. namespace facebook {
  11. namespace react {
  12. /*
  13. * State for <ScrollView> component.
  14. */
  15. class ScrollViewState final {
  16. public:
  17. Point contentOffset;
  18. Rect contentBoundingRect;
  19. /*
  20. * Returns size of scrollable area.
  21. */
  22. Size getContentSize() const;
  23. #ifdef ANDROID
  24. ScrollViewState() = default;
  25. ScrollViewState(ScrollViewState const &previousState, folly::dynamic data)
  26. : contentOffset({(Float)data["contentOffsetLeft"].getDouble(),
  27. (Float)data["contentOffsetTop"].getDouble()}),
  28. contentBoundingRect({}){};
  29. folly::dynamic getDynamic() const {
  30. return folly::dynamic::object("contentOffsetLeft", contentOffset.x)(
  31. "contentOffsetTop", contentOffset.y);
  32. };
  33. #endif
  34. };
  35. } // namespace react
  36. } // namespace facebook