Skip to content

Commit

Permalink
Create iPadOS version (#111)
Browse files Browse the repository at this point in the history
feat: create iPadOS version

closes #3
  • Loading branch information
lui5fl authored Oct 6, 2024
1 parent 00b4ed0 commit e29641b
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 26 deletions.
38 changes: 26 additions & 12 deletions Hax.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
A0999DFC2C6518B6008B62B6 /* TipJarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0999DFB2C6518B6008B62B6 /* TipJarView.swift */; };
A09DE87D2C8F57F300146418 /* SearchViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A09DE87C2C8F57F300146418 /* SearchViewModelTests.swift */; };
A0A2881829521A0500CF1484 /* FeedViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A2881729521A0500CF1484 /* FeedViewModelTests.swift */; };
A0A9F2AB2CB0832800D2A54E /* PadContentMargins.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A9F2AA2CB0832800D2A54E /* PadContentMargins.swift */; };
A0AC532A2CA1DC9A00872903 /* HaxWatch.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = A0AC531D2CA1DC9900872903 /* HaxWatch.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
A0AC53352CA1DCBF00872903 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A0AC532F2CA1DCBF00872903 /* Preview Assets.xcassets */; };
A0AC53362CA1DCBF00872903 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A0AC53312CA1DCBF00872903 /* Assets.xcassets */; };
Expand Down Expand Up @@ -361,6 +362,7 @@
A0999DFB2C6518B6008B62B6 /* TipJarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TipJarView.swift; sourceTree = "<group>"; };
A09DE87C2C8F57F300146418 /* SearchViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewModelTests.swift; sourceTree = "<group>"; };
A0A2881729521A0500CF1484 /* FeedViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedViewModelTests.swift; sourceTree = "<group>"; };
A0A9F2AA2CB0832800D2A54E /* PadContentMargins.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PadContentMargins.swift; sourceTree = "<group>"; };
A0AC531D2CA1DC9900872903 /* HaxWatch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HaxWatch.app; sourceTree = BUILT_PRODUCTS_DIR; };
A0AC532F2CA1DCBF00872903 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
A0AC53312CA1DCBF00872903 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -763,6 +765,7 @@
children = (
A08FDE2F2BEF7DBC00FB0265 /* Components */,
A08FDE302BEF7DC000FB0265 /* Screens */,
A0A9F2A92CB0831700D2A54E /* View Modifiers */,
);
path = Presentation;
sourceTree = "<group>";
Expand Down Expand Up @@ -877,6 +880,14 @@
path = Screens;
sourceTree = "<group>";
};
A0A9F2A92CB0831700D2A54E /* View Modifiers */ = {
isa = PBXGroup;
children = (
A0A9F2AA2CB0832800D2A54E /* PadContentMargins.swift */,
);
path = "View Modifiers";
sourceTree = "<group>";
};
A0AC53302CA1DCBF00872903 /* Preview Content */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1414,6 +1425,7 @@
A05938222BCA97E10042802D /* KeywordFilter.swift in Sources */,
A03739C92C7F75A400DEE078 /* AlgoliaSearchResultDTO.swift in Sources */,
A0F4DB2928D4EA3F006CD8E7 /* ItemRowView.swift in Sources */,
A0A9F2AB2CB0832800D2A54E /* PadContentMargins.swift in Sources */,
A0F4DB0028D4EA25006CD8E7 /* UserDefaultsExtension.swift in Sources */,
A03389602BEE9B810019F782 /* AlgoliaAPI.swift in Sources */,
A0DD98142C82129E00CBFC7F /* ItemList.swift in Sources */,
Expand Down Expand Up @@ -1591,7 +1603,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 2.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.luisfl.Hax.debug.HaxWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -1625,7 +1637,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 2.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.luisfl.Hax.HaxWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -1784,7 +1796,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 12.3;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 2.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.luisfl.Hax.debug;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand All @@ -1794,7 +1806,7 @@
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
Expand Down Expand Up @@ -1828,7 +1840,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 12.3;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 2.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.luisfl.Hax;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand All @@ -1838,7 +1850,7 @@
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
Expand Down Expand Up @@ -1956,14 +1968,14 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = Hax;
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = com.luisfl.Hax.debug;
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = "$(WK_COMPANION_APP_BUNDLE_IDENTIFIER)";
INFOPLIST_KEY_WKRunsIndependentlyOfCompanionApp = NO;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 2.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.luisfl.Hax.debug.HaxWatch;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = watchos;
Expand All @@ -1973,6 +1985,7 @@
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 11.0;
WK_COMPANION_APP_BUNDLE_IDENTIFIER = com.luisfl.Hax.debug;
};
name = Debug;
};
Expand All @@ -1992,14 +2005,14 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = Hax;
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = com.luisfl.Hax.debug;
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = "$(WK_COMPANION_APP_BUNDLE_IDENTIFIER)";
INFOPLIST_KEY_WKRunsIndependentlyOfCompanionApp = NO;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 2.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.luisfl.Hax.HaxWatch;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = watchos;
Expand All @@ -2009,6 +2022,7 @@
TARGETED_DEVICE_FAMILY = 4;
VALIDATE_PRODUCT = YES;
WATCHOS_DEPLOYMENT_TARGET = 11.0;
WK_COMPANION_APP_BUNDLE_IDENTIFIER = com.luisfl.Hax;
};
name = Release;
};
Expand All @@ -2031,7 +2045,7 @@
"@executable_path/../../Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 2.0.0;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
Expand Down Expand Up @@ -2070,7 +2084,7 @@
"@executable_path/../../Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 2.0.0;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
Expand Down
21 changes: 10 additions & 11 deletions Hax/Presentation/Components/Views/TranslateButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ struct TranslateButton: View {
// MARK: Body

var body: some View {
Group {
if let text {
Button {
translationPopoverIsPresented = true
textToBeTranslated = text
} label: {
Label(
"Translate…",
systemImage: "arrow.left.arrow.right"
)
}
if UIDevice.current.userInterfaceIdiom == .phone,
let text {
Button {
translationPopoverIsPresented = true
textToBeTranslated = text
} label: {
Label(
"Translate…",
systemImage: "arrow.left.arrow.right"
)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Hax/Presentation/Screens/Views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct MainView<Model: MainViewModelProtocol>: View {
.presentationDetents([.medium, .large])
.id(user.string)
}
.modifier(PadContentMargins())
}
}

Expand Down
1 change: 1 addition & 0 deletions Hax/Presentation/Screens/Views/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct SearchView: View {
.searchable(
text: $model.text,
isPresented: $searchBarIsPresented,
placement: .navigationBarDrawer,
prompt: "Title"
)
.translationPresentation(
Expand Down
1 change: 1 addition & 0 deletions Hax/Presentation/Screens/Views/UserView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct UserView<Model: UserViewModelProtocol>: View {
ActivityIndicatorView()
}
}
.contentMargins(.horizontal, nil, for: .scrollContent)
.onAppear {
Task {
await model.onViewAppear()
Expand Down
40 changes: 40 additions & 0 deletions Hax/Presentation/View Modifiers/PadContentMargins.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// PadContentMargins.swift
// Hax
//
// Created by Luis Fariña on 4/10/24.
//

import SwiftUI

struct PadContentMargins: ViewModifier {

// MARK: Properties

@Environment(
\.horizontalSizeClass
) private var horizontalSizeClass

// MARK: Body

func body(content: Content) -> some View {
if UIDevice.current.userInterfaceIdiom == .pad {
GeometryReader { proxy in
let width = UIScreen.main.bounds.width
let length: CGFloat? = if horizontalSizeClass == .regular,
proxy.size.width > proxy.size.height {
(width - width * 2 / 3) / 2
} else {
nil
}
content.contentMargins(
.horizontal,
length,
for: .scrollContent
)
}
} else {
content
}
}
}
26 changes: 23 additions & 3 deletions HaxWidget/HaxWidgetBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,29 @@ struct HaxWidgetBundle: WidgetBundle {
// MARK: Body

var body: some Widget {
HaxWidget()
if #available(iOSApplicationExtension 18.0, *) {
HaxWidgetControl()
if #available(iOS 18.0, *) {
return iOS18Body
} else {
return iOS17Body
}
}
}

// MARK: - Private extension

private extension HaxWidgetBundle {

// MARK: Properties

@WidgetBundleBuilder
@available(iOSApplicationExtension 18.0, *)
var iOS18Body: some Widget {
HaxWidget()
HaxWidgetControl()
}

@WidgetBundleBuilder
var iOS17Body: some Widget {
HaxWidget()
}
}
3 changes: 3 additions & 0 deletions HaxWidget/Widgets/HaxWidget/HaxWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ struct HaxWidget: Widget {
}
.configurationDisplayName("Feed")
.description("Displays the latest stories from the specified feed.")
.supportedFamilies(
[.systemSmall, .systemMedium, .systemLarge]
)
}
}

Expand Down

0 comments on commit e29641b

Please sign in to comment.