Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 32c8452

Browse files
committedMay 22, 2025·
accomodate different coordinate systems in ios and macos
1 parent 9bb30df commit 32c8452

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed
 

‎ios_platform_views_io_2025/acrings_native/common/ACRings.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ struct ACRings: View {
55
var percentExercise: Double = 0.50
66
var percentStand: Double = 0.75
77

8+
// iOS and MacOS have differing coordinate systems
9+
// In iOS, 0,0 is top-left, whereas in MacOS, 0,0 is bottom right
10+
// Also circles are draw with their center at 0,0 so they must
11+
// be translated accordingly
12+
var offsetX = 150.0
13+
#if os(iOS)
14+
var offsetY = 150.0
15+
#elseif os(macOS)
16+
var offsetY = -150.0
17+
#endif
18+
819
var body: some View {
920
ZStack {
1021
// background
@@ -29,7 +40,6 @@ struct ACRings: View {
2940
.stroke(.blue, lineWidth: 20).frame(width: 100, height: 200)
3041

3142

32-
}.rotationEffect(.degrees(-90))
33-
43+
}.rotationEffect(.degrees(-90)).offset(x:offsetX, y:offsetY)
3444
}
3545
}

‎ios_platform_views_io_2025/acrings_native/macos/Classes/ACRingsNativeViewFactory.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ class NativeView: NSView {
3333
arguments args: Any?,
3434
binaryMessenger messenger: FlutterBinaryMessenger?
3535
) {
36-
super.init(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
37-
wantsLayer = true
38-
layer?.backgroundColor = NSColor.systemBlue.cgColor
36+
super.init(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
37+
//wantsLayer = true
3938
// macOS views can be created here
4039
createNativeView(view: self)
4140
}
@@ -45,6 +44,7 @@ class NativeView: NSView {
4544
}
4645

4746
func createNativeView(view _view: NSView) {
48-
window?.contentView = NSHostingView(rootView: ACRings())
47+
let hostingView = NSHostingView(rootView: ACRings())
48+
self.addSubview(hostingView)
4949
}
5050
}

‎ios_platform_views_io_2025/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class _MyHomePageState extends State<MyHomePage> {
5252
child: Column(
5353
mainAxisAlignment: MainAxisAlignment.center,
5454
children: <Widget>[
55-
SizedBox(height: 200, width: 0,
55+
SizedBox(height: 300, width: 300,
5656
child:
5757
ActivityRings()),
5858
Text("Move", style: textTheme.displaySmall?.copyWith(color: Colors.red, fontWeight: FontWeight.bold),),

0 commit comments

Comments
 (0)
Please sign in to comment.