Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 7c2cc59

Browse files
Merge branch '4.8.0' into 5.0.0
2 parents accf975 + 6006b0d commit 7c2cc59

File tree

5 files changed

+100
-85
lines changed

5 files changed

+100
-85
lines changed

Xamarin.Forms.Controls/GalleryPages/ScrollGallery.cs

Lines changed: 84 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -11,112 +11,121 @@ public class ScrollGallery : ContentPage
1111
readonly ScrollView _scrollview;
1212
readonly StackLayout _stack;
1313
ScrollOrientation _orientation;
14-
List<Button> _buttons = new List<Button> ();
14+
List<Button> _buttons = new List<Button>();
1515
Button _toNavigateTo;
16-
public ScrollGallery (ScrollOrientation orientation = ScrollOrientation.Vertical)
16+
public ScrollGallery(ScrollOrientation orientation = ScrollOrientation.Vertical)
1717
{
1818
_orientation = orientation;
19-
var root = new Grid ();
20-
root.RowDefinitions.Add (new RowDefinition () { Height = GridLength.Auto });
21-
root.RowDefinitions.Add (new RowDefinition () { Height = GridLength.Auto });
22-
root.RowDefinitions.Add (new RowDefinition () { Height = GridLength.Auto });
23-
root.RowDefinitions.Add (new RowDefinition ());
19+
var root = new Grid();
20+
root.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
21+
root.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
22+
root.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
23+
root.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
24+
root.RowDefinitions.Add(new RowDefinition());
2425

2526
var btnStack1 = new StackLayout { Orientation = StackOrientation.Horizontal };
26-
var btnStack = new StackLayout { Orientation = StackOrientation.Horizontal };
27+
var btnStack2 = new StackLayout { Orientation = StackOrientation.Horizontal };
28+
var btnStack3 = new StackLayout { Orientation = StackOrientation.Horizontal };
29+
2730
var btn = new Button { Text = "Scroll to 100" };
2831
var btn4 = new Button { Text = "Scroll to 100 no anim" };
2932
var btn1 = new Button { Text = "Start" };
3033
var btn2 = new Button { Text = "Center" };
3134
var btn3 = new Button { Text = "End" };
32-
var btn7 = new Button { Text = "Toggle Scroll Bar Visibility" };
33-
var btn6 = new Button { Text = "MakeVisible", HorizontalOptions= LayoutOptions.CenterAndExpand, BackgroundColor = Color.Accent };
34-
var btn8 = new Button { Text = "Toggle Orientation" };
35-
var btn9 = new Button { Text = "Default Scroll Bar Visibility" };
35+
var btn7 = new Button { Text = "Toggle Scroll Bar Visibility", WidthRequest = 120 };
36+
var btn6 = new Button { Text = "MakeVisible", HorizontalOptions = LayoutOptions.CenterAndExpand, BackgroundColor = Color.Accent };
37+
var btn8 = new Button { Text = "Toggle Orientation", WidthRequest = 120 };
38+
var btn9 = new Button { Text = "Default Scroll Bar Visibility", WidthRequest = 120 };
3639

3740
var labelStack = new StackLayout { Orientation = StackOrientation.Horizontal };
38-
var label = new Label { Text = string.Format ("X: {0}, Y: {1}", 0, 0) };
41+
var label = new Label { Text = string.Format("X: {0}, Y: {1}", 0, 0) };
3942
var scrollStatusLabel = new Label { Text = string.Empty };
40-
41-
root.Children.Add (labelStack);
42-
root.Children.Add (btnStack);
43-
root.Children.Add (btnStack1);
4443

45-
btnStack.Children.Add (btn1);
46-
btnStack.Children.Add (btn2);
47-
btnStack.Children.Add (btn3);
48-
btnStack.Children.Add(btn7);
49-
btnStack.Children.Add(btn9);
50-
btnStack.Children.Add(btn8);
44+
root.Children.Add(labelStack);
45+
root.Children.Add(btnStack1);
46+
root.Children.Add(btnStack2);
47+
root.Children.Add(btnStack3);
48+
49+
btnStack1.Children.Add(btn1);
50+
btnStack1.Children.Add(btn2);
51+
btnStack1.Children.Add(btn3);
52+
53+
btnStack2.Children.Add(btn);
54+
btnStack2.Children.Add(btn4);
5155

52-
btnStack1.Children.Add (btn);
53-
btnStack1.Children.Add (btn4);
56+
btnStack3.Children.Add(btn7);
57+
btnStack3.Children.Add(btn9);
58+
btnStack3.Children.Add(btn8);
5459

5560
labelStack.Children.Add(label);
5661
labelStack.Children.Add(scrollStatusLabel);
5762

58-
Grid.SetRow (btnStack, 1);
59-
Grid.SetRow (btnStack1, 2);
60-
61-
var grid = new Grid ();
62-
grid.RowDefinitions.Add (new RowDefinition { Height = GridLength.Auto });
63-
grid.RowDefinitions.Add (new RowDefinition ());
64-
_stack = new StackLayout ();
65-
Grid.SetRow (_stack, 1);
66-
grid.Children.Add (btn6);
67-
grid.Children.Add (_stack);
68-
_scrollview = new ScrollView {
69-
AutomationId="thescroller",
63+
Grid.SetRow(btnStack1, 1);
64+
Grid.SetRow(btnStack2, 2);
65+
Grid.SetRow(btnStack3, 3);
66+
67+
var grid = new Grid();
68+
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
69+
grid.RowDefinitions.Add(new RowDefinition());
70+
_stack = new StackLayout();
71+
Grid.SetRow(_stack, 1);
72+
grid.Children.Add(btn6);
73+
grid.Children.Add(_stack);
74+
_scrollview = new ScrollView
75+
{
76+
AutomationId = "thescroller",
7077
BackgroundColor = Color.Aqua,
7178
Content = grid
7279
};
73-
root.Children.Add (_scrollview);
74-
Grid.SetRow (_scrollview, 3);
80+
root.Children.Add(_scrollview);
81+
Grid.SetRow(_scrollview, 4);
7582

76-
_scrollview.Scrolled+= (object sender, ScrolledEventArgs e) => {
77-
label.Text = string.Format ("X: {0}, Y: {1}", e.ScrollX, e.ScrollY);
83+
_scrollview.Scrolled += (object sender, ScrolledEventArgs e) => {
84+
label.Text = string.Format("X: {0}, Y: {1}", e.ScrollX, e.ScrollY);
7885
};
7986

8087
btn.Clicked += async (object sender, EventArgs e) => {
8188
scrollStatusLabel.Text = "scrolling";
82-
switch (orientation) {
89+
switch (orientation)
90+
{
8391
case ScrollOrientation.Horizontal:
84-
await _scrollview.ScrollToAsync (100, 0, true);
92+
await _scrollview.ScrollToAsync(100, 0, true);
8593
break;
8694
case ScrollOrientation.Vertical:
87-
await _scrollview.ScrollToAsync (0, 100, true);
95+
await _scrollview.ScrollToAsync(0, 100, true);
8896
break;
8997
case ScrollOrientation.Both:
90-
await _scrollview.ScrollToAsync (100, 100, true);
98+
await _scrollview.ScrollToAsync(100, 100, true);
9199
break;
92100
}
93101
scrollStatusLabel.Text = "completed";
94102
};
95103
btn4.Clicked += async (object sender, EventArgs e) => {
96-
switch (orientation) {
104+
switch (orientation)
105+
{
97106
case ScrollOrientation.Horizontal:
98-
await _scrollview.ScrollToAsync (100, 0, false);
107+
await _scrollview.ScrollToAsync(100, 0, false);
99108
break;
100109
case ScrollOrientation.Vertical:
101-
await _scrollview.ScrollToAsync (0, 100, false);
110+
await _scrollview.ScrollToAsync(0, 100, false);
102111
break;
103112
case ScrollOrientation.Both:
104-
await _scrollview.ScrollToAsync (100, 100, true);
113+
await _scrollview.ScrollToAsync(100, 100, true);
105114
break;
106115
}
107116
};
108117

109118
btn1.Clicked += async (object sender, EventArgs e) => {
110-
await _scrollview.ScrollToAsync (_toNavigateTo, ScrollToPosition.Start, true);
119+
await _scrollview.ScrollToAsync(_toNavigateTo, ScrollToPosition.Start, true);
111120
};
112121
btn2.Clicked += async (object sender, EventArgs e) => {
113-
await _scrollview.ScrollToAsync (_toNavigateTo, ScrollToPosition.Center, true);
122+
await _scrollview.ScrollToAsync(_toNavigateTo, ScrollToPosition.Center, true);
114123
};
115124
btn3.Clicked += async (object sender, EventArgs e) => {
116-
await _scrollview.ScrollToAsync (_toNavigateTo, ScrollToPosition.End, true);
125+
await _scrollview.ScrollToAsync(_toNavigateTo, ScrollToPosition.End, true);
117126
};
118127
btn6.Clicked += async (object sender, EventArgs e) => {
119-
await _scrollview.ScrollToAsync (_toNavigateTo, ScrollToPosition.MakeVisible, true);
128+
await _scrollview.ScrollToAsync(_toNavigateTo, ScrollToPosition.MakeVisible, true);
120129
};
121130
btn7.Clicked += (object sender, EventArgs e) =>
122131
{
@@ -151,53 +160,58 @@ public ScrollGallery (ScrollOrientation orientation = ScrollOrientation.Vertical
151160
_scrollview.HorizontalScrollBarVisibility = ScrollBarVisibility.Default;
152161
};
153162

154-
_stack.Padding = new Size (20, 60);
163+
_stack.Padding = new Size(20, 60);
155164

156-
PopulateStack (_stack);
165+
PopulateStack(_stack);
157166

158167
_scrollview.Orientation = _orientation;
159168

160-
if (orientation == ScrollOrientation.Horizontal || orientation == ScrollOrientation.Both) {
169+
if (orientation == ScrollOrientation.Horizontal || orientation == ScrollOrientation.Both)
170+
{
161171
_stack.Orientation = StackOrientation.Horizontal;
162172
}
163173

164-
if (orientation == ScrollOrientation.Both) {
165-
var stack2 = new StackLayout ();
166-
PopulateStack (stack2);
167-
_stack.Children.Add (stack2);
174+
if (orientation == ScrollOrientation.Both)
175+
{
176+
var stack2 = new StackLayout();
177+
PopulateStack(stack2);
178+
_stack.Children.Add(stack2);
168179
}
169180

170181
Content = root;
171182
}
172183

173-
void PopulateStack (StackLayout stack)
184+
void PopulateStack(StackLayout stack)
174185
{
175-
for (int i = 0; i < 100; i++) {
186+
for (int i = 0; i < 100; i++)
187+
{
176188

177-
var newButton = new Button { Text = "Foo Bar", AutomationId =string.Format ("btn_{0}", i) };
189+
var newButton = new Button { Text = "Foo Bar", AutomationId = string.Format("btn_{0}", i) };
178190
if (i == 49)
179191
newButton.Text = "the before";
180192

181-
if (i == 50) {
193+
if (i == 50)
194+
{
182195
newButton.Text = "the scrollto button";
183196
newButton.BackgroundColor = Color.Yellow;
184197
newButton.TextColor = Color.Black;
185198
_toNavigateTo = newButton;
186199
}
187200
if (i == 51)
188201
newButton.Text = "the after";
189-
if (i == 53) {
202+
if (i == 53)
203+
{
190204
newButton.Text = "the make visible from start";
191205
newButton.Clicked += async (object sender, EventArgs e) => {
192-
await _scrollview.ScrollToAsync (_toNavigateTo, ScrollToPosition.MakeVisible, true);
206+
await _scrollview.ScrollToAsync(_toNavigateTo, ScrollToPosition.MakeVisible, true);
193207
};
194208
}
195209

196-
_buttons.Add (newButton);
197-
stack.Children.Add (newButton);
210+
_buttons.Add(newButton);
211+
stack.Children.Add(newButton);
198212
}
199213

200-
stack.Children.Add (new Button { Text = "Foo Bottom" });
214+
stack.Children.Add(new Button { Text = "Foo Bottom" });
201215
}
202216
}
203-
}
217+
}

Xamarin.Forms.Core/ListView.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ public class ListView : ItemsView<Cell>, IListViewController, IElementConfigurat
1616
{
1717
readonly List<Element> _logicalChildren = new List<Element>();
1818

19-
#if NETSTANDARD1_0
20-
ReadOnlyCollection<Element> _readOnlyLogicalChildren;
21-
internal override ReadOnlyCollection<Element> LogicalChildrenInternal => _readOnlyLogicalChildren ??
22-
(_readOnlyLogicalChildren = new ReadOnlyCollection<Element>(_logicalChildren));
23-
#else
24-
internal override ReadOnlyCollection<Element> LogicalChildrenInternal => _logicalChildren.AsReadOnly();
25-
#endif
26-
2719
public static readonly BindableProperty IsPullToRefreshEnabledProperty = BindableProperty.Create("IsPullToRefreshEnabled", typeof(bool), typeof(ListView), false);
2820

2921
public static readonly BindableProperty IsRefreshingProperty = BindableProperty.Create("IsRefreshing", typeof(bool), typeof(ListView), false, BindingMode.TwoWay);
@@ -59,7 +51,7 @@ public class ListView : ItemsView<Cell>, IListViewController, IElementConfigurat
5951
public static readonly BindableProperty SeparatorColorProperty = BindableProperty.Create("SeparatorColor", typeof(Color), typeof(ListView), Color.Default);
6052

6153
public static readonly BindableProperty RefreshControlColorProperty = BindableProperty.Create(nameof(RefreshControlColor), typeof(Color), typeof(ListView), Color.Default);
62-
54+
6355
public static readonly BindableProperty HorizontalScrollBarVisibilityProperty = BindableProperty.Create(nameof(HorizontalScrollBarVisibility), typeof(ScrollBarVisibility), typeof(ListView), ScrollBarVisibility.Default);
6456

6557
public static readonly BindableProperty VerticalScrollBarVisibilityProperty = BindableProperty.Create(nameof(VerticalScrollBarVisibility), typeof(ScrollBarVisibility), typeof(ListView), ScrollBarVisibility.Default);
@@ -407,7 +399,7 @@ protected override void UnhookContent(Cell content)
407399
if (content == null || !_logicalChildren.Contains(content))
408400
return;
409401
var index = _logicalChildren.IndexOf(content);
410-
_logicalChildren.Remove(content);
402+
_logicalChildren.Remove(content);
411403
content.Parent = null;
412404
VisualDiagnostics.OnChildRemoved(this, content, index);
413405

@@ -698,4 +690,4 @@ protected override bool ValidateItemTemplate(DataTemplate template)
698690
return true;
699691
}
700692
}
701-
}
693+
}

Xamarin.Forms.Platform.Android/Renderers/ScrollViewRenderer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public class ScrollViewRenderer : NestedScrollView, IVisualElementRenderer, IEff
2828
LayoutDirection _prevLayoutDirection = LayoutDirection.Ltr;
2929
bool _checkedForRtlScroll = false;
3030

31-
public ScrollViewRenderer(Context context) : base(context)
31+
public ScrollViewRenderer(Context context) : base(
32+
new ContextThemeWrapper(context, Resource.Style.scrollViewTheme), null,
33+
Resource.Attribute.scrollViewStyle)
3234
{
3335
}
3436

Xamarin.Forms.Platform.Android/Resources/values/attrs.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@
1010
<attr name="collectionViewStyle" format="reference"/>
1111
</declare-styleable>
1212

13+
<declare-styleable name="ScrollViewRendererTheme">
14+
<attr name="scrollViewStyle" format="reference"/>
15+
</declare-styleable>
16+
1317
</resources>

Xamarin.Forms.Platform.Android/Resources/values/styles.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
attribute defined in attrs.xml), we can apply the collectionViewScrollBars style explicitly to the renderer we are
1313
creating (and avoid forcing every child control to have scrollbars).
1414
-->
15-
16-
<style name="collectionViewScrollBars">
15+
<style name="scrollViewScrollBars">
1716
<item name="android:scrollbars">vertical|horizontal</item>
1817
</style>
1918

2019
<style name="collectionViewTheme">
21-
<item name="collectionViewStyle">@style/collectionViewScrollBars</item>
20+
<item name="collectionViewStyle">@style/scrollViewScrollBars</item>
21+
</style>
22+
23+
<style name="scrollViewTheme">
24+
<item name="scrollViewStyle">@style/scrollViewScrollBars</item>
2225
</style>
2326

2427
<style name="MainTheme" parent="MainTheme.Base">

0 commit comments

Comments
 (0)