1use crate::ViewExt;
12pub use repose_core::scroll::{HorizontalScrollState, ScrollPhysics, ScrollState, ScrollStateXY};
13use repose_core::*;
14use std::rc::Rc;
15
16pub fn remember_scroll_state(key: impl Into<String>) -> Rc<ScrollState> {
18 repose_core::remember_with_key(key.into(), ScrollState::new)
19}
20
21pub fn remember_horizontal_scroll_state(key: impl Into<String>) -> Rc<HorizontalScrollState> {
22 repose_core::remember_with_key(key.into(), HorizontalScrollState::new)
23}
24
25pub fn remember_scroll_state_xy(key: impl Into<String>) -> Rc<ScrollStateXY> {
26 repose_core::remember_with_key(key.into(), ScrollStateXY::new)
27}
28
29pub fn ScrollArea(modifier: Modifier, state: Rc<ScrollState>, content: View) -> View {
39 let binding = state.to_binding();
40 let on_scroll_with_source = match &binding {
41 ScrollBinding::Vertical(b) => b.on_scroll_with_source.clone(),
42 _ => unreachable!(),
43 };
44 let modifier = modifier.vertical_scroll(match binding {
45 ScrollBinding::Vertical(b) => b,
46 _ => unreachable!(),
47 });
48 let modifier = match on_scroll_with_source {
49 Some(handler) => modifier.on_scroll_with_source(move |d, s| handler(d, s)),
50 None => modifier,
51 };
52 let content = crate::Box(
53 Modifier::new()
54 .flex_shrink(0.0)
55 .fill_max_width(),
58 )
59 .child(content);
60
61 View::new(0, ViewKind::Box)
62 .modifier(modifier)
63 .with_children(vec![content])
64}
65
66pub fn HorizontalScrollArea(
71 modifier: Modifier,
72 state: Rc<HorizontalScrollState>,
73 content: View,
74) -> View {
75 let binding = state.to_binding();
76 let on_scroll_with_source = match &binding {
77 ScrollBinding::Horizontal(b) => b.on_scroll_with_source.clone(),
78 _ => unreachable!(),
79 };
80 let modifier = modifier.horizontal_scroll(match binding {
81 ScrollBinding::Horizontal(b) => b,
82 _ => unreachable!(),
83 });
84 let modifier = match on_scroll_with_source {
85 Some(handler) => modifier.on_scroll_with_source(move |d, s| handler(d, s)),
86 None => modifier,
87 };
88 let content = crate::Box(
89 Modifier::new()
90 .flex_shrink(0.0)
91 .fill_max_height(),
94 )
95 .child(content);
96
97 View::new(0, ViewKind::Box)
98 .modifier(modifier)
99 .with_children(vec![content])
100}
101
102pub fn ScrollAreaXY(modifier: Modifier, state: Rc<ScrollStateXY>, content: View) -> View {
107 let binding = state.to_binding();
108 let on_scroll_with_source = match &binding {
109 ScrollBinding::Both(b) => b.on_scroll_with_source.clone(),
110 _ => unreachable!(),
111 };
112 let modifier = modifier.scrollable(match binding {
113 ScrollBinding::Both(b) => b,
114 _ => unreachable!(),
115 });
116 let modifier = match on_scroll_with_source {
117 Some(handler) => modifier.on_scroll_with_source(move |d, s| handler(d, s)),
118 None => modifier,
119 };
120 let content = crate::Box(Modifier::new().flex_shrink(0.0)).child(content);
121
122 View::new(0, ViewKind::Box)
123 .modifier(modifier)
124 .with_children(vec![content])
125}