From d0abdd4332cc33a6a7385b7ec2c37dd81fbdab2c Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 30 Jan 2020 09:10:32 -0500 Subject: [PATCH 1/3] Allow scroll top to be data bound --- examples/ScrollView.re | 20 +++++++++++++++++++- src/UI_Components/ScrollView.re | 10 ++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/examples/ScrollView.re b/examples/ScrollView.re index fed70929c..f9a4b9c79 100644 --- a/examples/ScrollView.re +++ b/examples/ScrollView.re @@ -26,9 +26,27 @@ let innerBox = module Sample = { let%component make = () => { + let%hook (scrollTop, setScrollTop) = Hooks.state(0); let%hook (bounce, setBounce) = Hooks.state(true); + let handleScrollTop = s => setScrollTop(_ => Float.to_int(s)); + Console.out("scrollTop: "); + Console.log(scrollTop); + + + - + { + if (scrollTop != actualScrollTop) { + dispatch(ScrollUpdated(scrollTop)); + }; + None; + }, + ); let%hook (actualScrollTop, _bounceAnimationState, resetBouncingAnimation) = switch (bouncingState) { From 750f777495bc841fe3f3ccaf4c45fe0ae69a4f39 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 30 Jan 2020 09:54:55 -0500 Subject: [PATCH 2/3] Make ScrollView fully controllable --- examples/ScrollView.re | 5 +++-- src/UI_Components/ScrollView.re | 23 ++++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/examples/ScrollView.re b/examples/ScrollView.re index f9a4b9c79..807d2a7ae 100644 --- a/examples/ScrollView.re +++ b/examples/ScrollView.re @@ -39,7 +39,7 @@ module Sample = { style=Style.[ marginBottom(10), fontFamily("Roboto-Regular.ttf"), - fontSize(20), + fontSize(20.), ] /> - + setScrollTop(_ => v)}> { @@ -61,7 +62,10 @@ let%component make = Always, () => { if (scrollTop != actualScrollTop) { - dispatch(ScrollUpdated(scrollTop)); + switch (onScroll) { + | Some(f) => dispatch(ScrollUpdated(scrollTop)) + | None => () + }; }; None; }, @@ -124,11 +128,18 @@ let%component make = let isVerticalScrollbarVisible = maxHeight > 0; let isHorizontalScrollbarVisible = maxWidth > 0; + let updateScrollPos = v => { + dispatch(ScrollUpdated(v)); + switch (onScroll) { + | Some(f) => f(v) + | None => () + }; + }; let verticalScrollBar = isVerticalScrollbarVisible ? dispatch(ScrollUpdated(int_of_float(v)))} + onValueChanged={v => updateScrollPos(int_of_float(v))} minimumValue=0. maximumValue={float_of_int(maxHeight)} sliderLength={outerMeasurements.height} @@ -180,11 +191,13 @@ let%component make = | Bouncing(_) => () | Idle when !bounce && (isAtTop || isAtBottom) => let clampedScrollTop = isAtTop ? 0 : maxHeight; - dispatch(ScrollUpdated(clampedScrollTop)); + updateScrollPos(clampedScrollTop); | Idle when bounce && (isAtTop || isAtBottom) => setBouncingState(_ => Bouncing(- delta * 2)); - dispatch(ScrollUpdated(isAtTop ? 0 : maxHeight)); - | Idle => dispatch(ScrollUpdated(newScrollTop)) + updateScrollPos(isAtTop ? 0 : maxHeight); + | Idle => + dispatch(ScrollUpdated(newScrollTop)); + updateScrollPos(newScrollTop); }; }; (horizontalScrollbar, verticalScrollBar, scroll); From ea43ba33ec143a5a15b1e981be5a6e6820ef7411 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 30 Jan 2020 10:21:31 -0500 Subject: [PATCH 3/3] Fix CI --- src/UI_Components/ScrollView.re | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UI_Components/ScrollView.re b/src/UI_Components/ScrollView.re index 153aa7f1a..476ec16f6 100644 --- a/src/UI_Components/ScrollView.re +++ b/src/UI_Components/ScrollView.re @@ -63,7 +63,7 @@ let%component make = () => { if (scrollTop != actualScrollTop) { switch (onScroll) { - | Some(f) => dispatch(ScrollUpdated(scrollTop)) + | Some(_) => dispatch(ScrollUpdated(scrollTop)) | None => () }; };