Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "touch" to SharePlay in iOS 17 #12

Draft
wants to merge 1 commit into
base: feature/viewmodel-refactor
Choose a base branch
from
Draft
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
12 changes: 12 additions & 0 deletions Card Play.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
7C7560A4279F6927007E3DE1 /* SevensTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C7560A3279F6927007E3DE1 /* SevensTableView.swift */; };
7C8FED502A6F0E3C00C949A1 /* PlatformSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8FED4F2A6F0E3C00C949A1 /* PlatformSupport.swift */; };
7C8FED522A6F136600C949A1 /* GroupActivityView+AppKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8FED512A6F136600C949A1 /* GroupActivityView+AppKit.swift */; };
7C9169512AA37E4C00399476 /* Sevens+Transferable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C9169502AA37E4C00399476 /* Sevens+Transferable.swift */; };
7C91992E27A5921300BC5802 /* WinnerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C91992D27A5921300BC5802 /* WinnerView.swift */; };
7C91993227A59DD600BC5802 /* ConfettiSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 7C91993127A59DD600BC5802 /* ConfettiSwiftUI */; };
7C9277E227AECB5400511484 /* LoserView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C9277E127AECB5400511484 /* LoserView.swift */; };
@@ -81,6 +82,7 @@
7C7560A3279F6927007E3DE1 /* SevensTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SevensTableView.swift; sourceTree = "<group>"; };
7C8FED4F2A6F0E3C00C949A1 /* PlatformSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlatformSupport.swift; sourceTree = "<group>"; };
7C8FED512A6F136600C949A1 /* GroupActivityView+AppKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GroupActivityView+AppKit.swift"; sourceTree = "<group>"; };
7C9169502AA37E4C00399476 /* Sevens+Transferable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Sevens+Transferable.swift"; sourceTree = "<group>"; };
7C91992D27A5921300BC5802 /* WinnerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WinnerView.swift; sourceTree = "<group>"; };
7C9277E127AECB5400511484 /* LoserView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoserView.swift; sourceTree = "<group>"; };
7CA9E68C2A6F261E009CFA58 /* GroupSession+Hashable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GroupSession+Hashable.swift"; sourceTree = "<group>"; };
@@ -181,6 +183,7 @@
7C0AE71F279D943A005695FB /* SharePlay */ = {
isa = PBXGroup;
children = (
7C91694F2AA37E4200399476 /* Transferable */,
7C0AE720279D9446005695FB /* PlayTogether.swift */,
7C55556E284378FA000C6F2C /* GroupActivityView+UIKit.swift */,
7C8FED512A6F136600C949A1 /* GroupActivityView+AppKit.swift */,
@@ -248,6 +251,14 @@
path = Extensions;
sourceTree = "<group>";
};
7C91694F2AA37E4200399476 /* Transferable */ = {
isa = PBXGroup;
children = (
7C9169502AA37E4C00399476 /* Sevens+Transferable.swift */,
);
path = Transferable;
sourceTree = "<group>";
};
7CA9E68B2A6F2610009CFA58 /* GroupActivities */ = {
isa = PBXGroup;
children = (
@@ -417,6 +428,7 @@
7C7560A4279F6927007E3DE1 /* SevensTableView.swift in Sources */,
7C3E52E7279DC0300002DE88 /* SevensView.swift in Sources */,
7C3EB7122A9B34D5001038AC /* ViewModel.swift in Sources */,
7C9169512AA37E4C00399476 /* Sevens+Transferable.swift in Sources */,
7C3A068D27A1D18D00261364 /* MainMenu.swift in Sources */,
7C0AE721279D9446005695FB /* PlayTogether.swift in Sources */,
7C8FED502A6F0E3C00C949A1 /* PlatformSupport.swift in Sources */,
30 changes: 22 additions & 8 deletions Sources/Menus/Select Game/SelectGame.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import CardsModel
import Sevens
import GroupActivities
import SwiftUI

struct SelectGame: View {
@EnvironmentObject var model: ViewModel

@State private var gameType: (any Game.Type) = Sevens.self
@State private var gameType: String = "Sevens"
@State private var startNoActiveSession: Bool = false
@State private var presentSharePlayDialog: Bool = false

@@ -21,11 +22,11 @@ struct SelectGame: View {
Section {
Text("Select game:")

Picker(selection: $playerCount) {
Label("Sevens", systemImage: "7.circle.fill")
Picker(selection: $gameType) {
Label("Sevens", systemImage: "7.circle.fill").tag("Sevens")
// Extra games coming soon:
// Label("Hearts", systemImage: "heart.circle.fill")
// Label("Go Fish", systemImage: "fish.circle.fill")
// Label("Hearts", systemImage: "heart.circle.fill").tag("Hearts")
// Label("Go Fish", systemImage: "fish.circle.fill").tag("Go Fish")
} label: {
Text("Game type")
}.pickerStyle(.segmented)
@@ -46,7 +47,11 @@ struct SelectGame: View {
Text("Number of players")
}.pickerStyle(.segmented)
}


ShareLink(item: createGame(),
preview: SharePreview("Sevens", image: Image("Icon")))
.hidden()

Button {
Task {
await startGame()
@@ -108,15 +113,24 @@ struct SelectGame: View {
}
}

private func createGame() -> some Transferable & Game {
switch gameType {
case "Sevens":
return Sevens(players: playerCount)
default:
return Sevens(players: playerCount)
}
}

private func startLocalGame() {
let game = gameType.init(players: playerCount)
let game = createGame()
model.game = game
model.setPlayers((1..<playerCount).map(game.autoPlayer(index:)),
of: game)
}

private func activity() -> PlayTogether {
let game = gameType.init(players: playerCount)
let game = createGame()
return PlayTogether(game: game)
}
}
12 changes: 12 additions & 0 deletions Sources/Resources/Assets.xcassets/Icon.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "appstore1024.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions Sources/SharePlay/Transferable/Sevens+Transferable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import CoreTransferable
import GroupActivities
import Sevens


@available(iOS 17, macOS 14, *)
extension Sevens: Transferable {
public static var transferRepresentation: some TransferRepresentation {
GroupActivityTransferRepresentation { item in
PlayTogether(game: item)
}.visibility(.ownProcess)
}
}