Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "2640"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
33 changes: 29 additions & 4 deletions DemoApp/DemoApp Watch App/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,36 @@ import AppleWatchScreenSize
struct ContentView: View {
let screenSize = ScreenSize()

var cornerRadius: CGFloat {
//return 51 // experiment here
CGFloat(screenSize.cornerSize ?? 0)
}

var body: some View {
RoundedRectangle(cornerSize: CGSize(width: Double(screenSize.cornerSize ?? 0), height: Double(screenSize.cornerSize ?? 0)))
.stroke(lineWidth: 10.0)
.foregroundColor(.red)
.edgesIgnoringSafeArea(.all)
ZStack {
// This rectange will show up if the radius set too big
Rectangle()
.fill(.white)

RoundedRectangle(cornerRadius: cornerRadius)
.fill(.red)

guide.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)

guide.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topTrailing)

guide.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomLeading)

guide.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)
}
.edgesIgnoringSafeArea(.all)
}

var guide: some View {
Rectangle()
.stroke(lineWidth: 0.5)
.fill(.blue)
.frame(width: cornerRadius, height: cornerRadius)
}
}

Expand Down
14 changes: 9 additions & 5 deletions DemoApp/DemoApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1500;
LastUpgradeCheck = 2640;
TargetAttributes = {
E7257A062B823BE8005147CF = {
CreatedOnToolsVersion = 15.0;
Expand Down Expand Up @@ -187,7 +187,9 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = BF3L252F9X;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand All @@ -209,6 +211,7 @@
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
STRING_CATALOG_GENERATE_SYMBOLS = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
Expand Down Expand Up @@ -248,7 +251,9 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = BF3L252F9X;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand All @@ -263,6 +268,7 @@
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
STRING_CATALOG_GENERATE_SYMBOLS = YES;
SWIFT_COMPILATION_MODE = wholemodule;
};
name = Release;
Expand All @@ -275,12 +281,11 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"DemoApp Watch App/Preview Content\"";
DEVELOPMENT_TEAM = BF3L252F9X;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = DemoApp;
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = "";
INFOPLIST_KEY_WKWatchOnly = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -305,12 +310,11 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"DemoApp Watch App/Preview Content\"";
DEVELOPMENT_TEAM = BF3L252F9X;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = DemoApp;
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = "";
INFOPLIST_KEY_WKWatchOnly = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
28 changes: 16 additions & 12 deletions Sources/AppleWatchScreenSize/AppleWatchScreenSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ public struct ScreenSize: Hashable {

If no corner size is associated with the current screen size, it returns `nil`.
*/
public var cornerSize: Int? {
public var cornerSize: CGFloat? {
get {
let dic: [ScreenSize: Int?] = [
ScreenSize(width: 136, height: 170): nil,
ScreenSize(width: 156, height: 195): nil,
ScreenSize(width: 162, height: 197): 28,
ScreenSize(width: 176, height: 215): 38,
ScreenSize(width: 184, height: 224): 34,
ScreenSize(width: 198, height: 242): 41,
ScreenSize(width: 205, height: 251): 54,
ScreenSize(width: 187, height: 223): 45,
ScreenSize(width: 208, height: 248): 49
let dic: [ScreenSize: CGFloat?] = [
ScreenSize(width: 136, height: 170): nil, // 1, 2, and 3 - 38mm
ScreenSize(width: 156, height: 195): nil, // 1, 2, and 3 - 42mm
ScreenSize(width: 162, height: 197): 28, // 4, 5, 6, and SE (all) - 40mm
ScreenSize(width: 176, height: 215): 38, // 7, 8, and 9 - 41mm
ScreenSize(width: 184, height: 224): 34, // 4, 5, 6, and SE (all) - 44mm
ScreenSize(width: 187, height: 223): 45, // 10, 11 - 42mm
ScreenSize(width: 198, height: 242): 41, // 7, 8, and 9 - 45mm
ScreenSize(width: 205, height: 251): 54.5, // Ultra 1 & 2 - 49mm
ScreenSize(width: 208, height: 248): 51, // 10, 11 - 46mm
ScreenSize(width: 211, height: 257): 57, // Ultra 3 - 49mm
]
return dic[self] ?? nil
}
Expand All @@ -51,7 +52,10 @@ public struct ScreenSize: Hashable {
- Parameter width: The width dimension of the screen size. It defaults to the screen bounds' width of the current device.
- Parameter height: The height dimension of the screen size. It defaults to the screen bounds' height of the current device.
*/
public init(width: CGFloat = WKInterfaceDevice.current().screenBounds.size.width, height: CGFloat = WKInterfaceDevice.current().screenBounds.size.height) {
public init(
width: CGFloat = WKInterfaceDevice.current().screenBounds.size.width,
height: CGFloat = WKInterfaceDevice.current().screenBounds.size.height
) {
self.width = width
self.height = height
}
Expand Down