Skip to content

Commit ff99a1c

Browse files
authored
fix(ScrollView): 'scrollEnabled' prop should only disable scroll, not touch (microsoft#767)
Using the IsEnabled property disabled touch in addition to scroll. We'll need to keep some state about the current horizontal scroll status, but we can easily work around this by just disabling horizontal and vertical scroll. Fixes microsoft#764
1 parent da2e62c commit ff99a1c

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

ReactWindows/ReactNative/Views/Scroll/ReactScrollViewManager.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public class ReactScrollViewManager : ViewParentManager<ScrollViewer>
1818
{
1919
private const int CommandScrollTo = 1;
2020

21+
private readonly IDictionary<ScrollViewer, ScrollViewerData> _scrollViewerData =
22+
new Dictionary<ScrollViewer, ScrollViewerData>();
23+
2124
/// <summary>
2225
/// The name of the view manager.
2326
/// </summary>
@@ -99,7 +102,16 @@ public void SetBackgroundColor(ScrollViewer view, uint color)
99102
[ReactProp("scrollEnabled", DefaultBoolean = true)]
100103
public void SetEnabled(ScrollViewer view, bool enabled)
101104
{
102-
view.IsEnabled = enabled;
105+
if (enabled)
106+
{
107+
view.VerticalScrollMode = ScrollMode.Auto;
108+
view.HorizontalScrollMode = _scrollViewerData[view].HorizontalScrollMode;
109+
}
110+
else
111+
{
112+
view.VerticalScrollMode = ScrollMode.Disabled;
113+
view.HorizontalScrollMode = ScrollMode.Disabled;
114+
}
103115
}
104116

105117
/// <summary>
@@ -112,9 +124,11 @@ public void SetEnabled(ScrollViewer view, bool enabled)
112124
[ReactProp("horizontal")]
113125
public void SetHorizontal(ScrollViewer view, bool horizontal)
114126
{
115-
view.HorizontalScrollMode = horizontal
127+
var horizontalScrollMode = horizontal
116128
? ScrollMode.Auto
117129
: ScrollMode.Disabled;
130+
131+
view.HorizontalScrollMode = _scrollViewerData[view].HorizontalScrollMode = horizontalScrollMode;
118132
}
119133

120134
/// <summary>
@@ -255,6 +269,8 @@ public override void RemoveChildAt(ScrollViewer parent, int index)
255269
/// <param name="view">The view.</param>
256270
public override void OnDropViewInstance(ThemedReactContext reactContext, ScrollViewer view)
257271
{
272+
_scrollViewerData.Remove(view);
273+
258274
view.ViewChanging -= OnViewChanging;
259275
view.DirectManipulationStarted -= OnDirectManipulationStarted;
260276
view.DirectManipulationCompleted -= OnDirectManipulationCompleted;
@@ -292,13 +308,19 @@ public override void ReceiveCommand(ScrollViewer view, int commandId, JArray arg
292308
/// <returns>The view instance.</returns>
293309
protected override ScrollViewer CreateViewInstance(ThemedReactContext reactContext)
294310
{
295-
return new ScrollViewer
311+
var scrollViewerData = new ScrollViewerData();
312+
313+
var scrollViewer = new ScrollViewer
296314
{
297315
HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden,
298316
HorizontalScrollMode = ScrollMode.Disabled,
299317
VerticalScrollBarVisibility = ScrollBarVisibility.Hidden,
300318
VerticalScrollMode = ScrollMode.Auto,
301319
};
320+
321+
_scrollViewerData.Add(scrollViewer, scrollViewerData);
322+
323+
return scrollViewer;
302324
}
303325

304326
/// <summary>
@@ -453,5 +475,10 @@ public override void Dispatch(RCTEventEmitter eventEmitter)
453475
eventEmitter.receiveEvent(ViewTag, EventName, _data);
454476
}
455477
}
478+
479+
class ScrollViewerData
480+
{
481+
public ScrollMode HorizontalScrollMode = ScrollMode.Disabled;
482+
}
456483
}
457484
}

0 commit comments

Comments
 (0)