Skip to content

Commit a5bbba5

Browse files
github-actions[bot]PureWeen
authored andcommitted
[create-pull-request] automated change (#30700)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 96a8897 commit a5bbba5

File tree

1 file changed

+125
-125
lines changed

1 file changed

+125
-125
lines changed
Lines changed: 125 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#if IOS
2-
using UIKit;
32
using CoreGraphics;
43
using Microsoft.Maui.Handlers;
4+
using UIKit;
55
#endif
66

77
namespace Maui.Controls.Sample.Issues;
@@ -10,71 +10,71 @@ namespace Maui.Controls.Sample.Issues;
1010
[Issue(IssueTracker.Github, 30147, "MauiScrollView resets ContentOffset on first layout pass", PlatformAffected.iOS)]
1111
public class Issue30147 : ContentPage
1212
{
13-
Issue30147CustomScrollView myScroll;
14-
Label offsetLabel;
15-
16-
public Issue30147()
17-
{
18-
Title = "Issue 30147";
19-
20-
// Create the Label to display scroll offset
21-
offsetLabel = new Label
22-
{
23-
Text = "0",
13+
Issue30147CustomScrollView myScroll;
14+
Label offsetLabel;
15+
16+
public Issue30147()
17+
{
18+
Title = "Issue 30147";
19+
20+
// Create the Label to display scroll offset
21+
offsetLabel = new Label
22+
{
23+
Text = "0",
2424
AutomationId = "OffsetLabel",
25-
FontSize = 18
26-
};
27-
28-
// Create Header with offset display
29-
var headerLayout = new HorizontalStackLayout
30-
{
31-
Padding = new Thickness(20),
32-
BackgroundColor = Colors.LightGray,
33-
Children =
34-
{
35-
new Label
36-
{
37-
Text = "Offset: X = ",
38-
FontSize = 18
39-
},
40-
offsetLabel
41-
}
42-
};
43-
44-
// Create the CustomScrollView
45-
myScroll = new Issue30147CustomScrollView
46-
{
47-
Orientation = ScrollOrientation.Horizontal
48-
};
49-
50-
// Add the event handler for offset changes
51-
myScroll.OffsetChanged += (s, e) =>
52-
{
53-
offsetLabel.Text = e.X.ToString();
54-
};
55-
56-
// Create the content for the scroll view
57-
var scrollContent = new StackLayout();
58-
scrollContent.Add(new BoxView { Color = Colors.Red, HeightRequest = 300, WidthRequest = 2000 });
59-
60-
myScroll.Content = scrollContent;
61-
62-
// Create the Grid layout
63-
var grid = new Grid
64-
{
65-
RowDefinitions =
66-
{
67-
new RowDefinition { Height = GridLength.Auto },
68-
new RowDefinition { Height = GridLength.Star }
69-
}
70-
};
71-
72-
grid.Add(headerLayout, 0, 0);
73-
grid.Add(myScroll, 0, 1);
74-
75-
// Set the page content
76-
Content = grid;
77-
}
25+
FontSize = 18
26+
};
27+
28+
// Create Header with offset display
29+
var headerLayout = new HorizontalStackLayout
30+
{
31+
Padding = new Thickness(20),
32+
BackgroundColor = Colors.LightGray,
33+
Children =
34+
{
35+
new Label
36+
{
37+
Text = "Offset: X = ",
38+
FontSize = 18
39+
},
40+
offsetLabel
41+
}
42+
};
43+
44+
// Create the CustomScrollView
45+
myScroll = new Issue30147CustomScrollView
46+
{
47+
Orientation = ScrollOrientation.Horizontal
48+
};
49+
50+
// Add the event handler for offset changes
51+
myScroll.OffsetChanged += (s, e) =>
52+
{
53+
offsetLabel.Text = e.X.ToString();
54+
};
55+
56+
// Create the content for the scroll view
57+
var scrollContent = new StackLayout();
58+
scrollContent.Add(new BoxView { Color = Colors.Red, HeightRequest = 300, WidthRequest = 2000 });
59+
60+
myScroll.Content = scrollContent;
61+
62+
// Create the Grid layout
63+
var grid = new Grid
64+
{
65+
RowDefinitions =
66+
{
67+
new RowDefinition { Height = GridLength.Auto },
68+
new RowDefinition { Height = GridLength.Star }
69+
}
70+
};
71+
72+
grid.Add(headerLayout, 0, 0);
73+
grid.Add(myScroll, 0, 1);
74+
75+
// Set the page content
76+
Content = grid;
77+
}
7878
}
7979

8080
public class Issue30147ScrollOffsetChangedEventArgs : EventArgs
@@ -92,75 +92,75 @@ public Issue30147ScrollOffsetChangedEventArgs(double x, double y)
9292
// Custom ScrollView class for tracking offset changes
9393
public class Issue30147CustomScrollView : ScrollView
9494
{
95-
public event EventHandler<Issue30147ScrollOffsetChangedEventArgs> OffsetChanged;
95+
public event EventHandler<Issue30147ScrollOffsetChangedEventArgs> OffsetChanged;
9696

97-
// Raise the event from platform-specific code
98-
internal void RaiseOffsetChanged(double x, double y)
99-
{
100-
OffsetChanged?.Invoke(this, new Issue30147ScrollOffsetChangedEventArgs(x, y));
101-
}
97+
// Raise the event from platform-specific code
98+
internal void RaiseOffsetChanged(double x, double y)
99+
{
100+
OffsetChanged?.Invoke(this, new Issue30147ScrollOffsetChangedEventArgs(x, y));
101+
}
102102
}
103103

104104
#if IOS
105105
public class Issue30147CustomMauiScrollView : Microsoft.Maui.Platform.MauiScrollView
106106
{
107-
CGPoint _previousOffset = new(-1, -1);
108-
Issue30147CustomScrollView _virtualView;
109-
110-
public Issue30147CustomMauiScrollView(Issue30147CustomScrollView virtualView)
111-
{
112-
_virtualView = virtualView;
113-
}
114-
115-
public override void SetContentOffset(CGPoint contentOffset, bool animated)
116-
{
117-
base.SetContentOffset(contentOffset, animated);
118-
NotifyOffsetChanged(contentOffset);
119-
}
120-
121-
public override CGPoint ContentOffset
122-
{
123-
get => base.ContentOffset;
124-
set
125-
{
126-
base.ContentOffset = value;
127-
NotifyOffsetChanged(value);
128-
}
129-
}
130-
131-
void NotifyOffsetChanged(CGPoint offset)
132-
{
133-
if (_previousOffset.X != offset.X || _previousOffset.Y != offset.Y)
134-
{
135-
_previousOffset = offset;
136-
_virtualView?.RaiseOffsetChanged(offset.X, offset.Y);
137-
}
138-
}
107+
CGPoint _previousOffset = new(-1, -1);
108+
Issue30147CustomScrollView _virtualView;
109+
110+
public Issue30147CustomMauiScrollView(Issue30147CustomScrollView virtualView)
111+
{
112+
_virtualView = virtualView;
113+
}
114+
115+
public override void SetContentOffset(CGPoint contentOffset, bool animated)
116+
{
117+
base.SetContentOffset(contentOffset, animated);
118+
NotifyOffsetChanged(contentOffset);
119+
}
120+
121+
public override CGPoint ContentOffset
122+
{
123+
get => base.ContentOffset;
124+
set
125+
{
126+
base.ContentOffset = value;
127+
NotifyOffsetChanged(value);
128+
}
129+
}
130+
131+
void NotifyOffsetChanged(CGPoint offset)
132+
{
133+
if (_previousOffset.X != offset.X || _previousOffset.Y != offset.Y)
134+
{
135+
_previousOffset = offset;
136+
_virtualView?.RaiseOffsetChanged(offset.X, offset.Y);
137+
}
138+
}
139139
}
140140

141141
public class Issue30147CustomScrollViewHandler : ScrollViewHandler
142142
{
143-
bool _initialOffsetApplied = false;
144-
145-
protected override UIScrollView CreatePlatformView()
146-
{
147-
if (VirtualView is Issue30147CustomScrollView customScrollView)
148-
{
149-
return new Issue30147CustomMauiScrollView(customScrollView);
150-
}
151-
152-
return base.CreatePlatformView();
153-
}
154-
155-
public override void PlatformArrange(Rect frame)
156-
{
157-
base.PlatformArrange(frame);
158-
159-
if (!_initialOffsetApplied)
160-
{
161-
PlatformView.ContentOffset = new CGPoint(500, 0);
162-
_initialOffsetApplied = true;
163-
}
164-
}
143+
bool _initialOffsetApplied = false;
144+
145+
protected override UIScrollView CreatePlatformView()
146+
{
147+
if (VirtualView is Issue30147CustomScrollView customScrollView)
148+
{
149+
return new Issue30147CustomMauiScrollView(customScrollView);
150+
}
151+
152+
return base.CreatePlatformView();
153+
}
154+
155+
public override void PlatformArrange(Rect frame)
156+
{
157+
base.PlatformArrange(frame);
158+
159+
if (!_initialOffsetApplied)
160+
{
161+
PlatformView.ContentOffset = new CGPoint(500, 0);
162+
_initialOffsetApplied = true;
163+
}
164+
}
165165
}
166166
#endif

0 commit comments

Comments
 (0)