Skip to content

Instantly share code, notes, and snippets.

@noppefoxwolf
Created July 8, 2021 11:38
Show Gist options
  • Save noppefoxwolf/e1a529980d34ea5b3fc3b06f1a6e0b6e to your computer and use it in GitHub Desktop.
Save noppefoxwolf/e1a529980d34ea5b3fc3b06f1a6e0b6e to your computer and use it in GitHub Desktop.
Share.swift
//
// TCAModule.swift
//
//
// Created Tomoya Hirano on 2021/07/04.
// Copyright © 2021 ___ORGANIZATIONNAME___. All rights reserved.
//
//
import SwiftUI
import ComposableArchitecture
/// シェア用のTCAコンポーネント
public enum Share {}
public extension Share {
struct View: SwiftUI.View {
let store: Store<State, Action>
public var body: some SwiftUI.View {
WithViewStore(store) { (viewStore) in
ActivityViewController(activityItems: [viewStore.body, viewStore.item.image] as [AnyObject])
}
}
}
struct State: Equatable {
struct Item: Equatable {
let title: String
let artist: String
let image: UIImage
}
let item: Item
var body: String { "\(item.title) - \(item.artist) #np ." }
}
enum Action: Equatable {
}
struct Environment {
}
static let reducer = Reducer<State, Action, Environment> { state, action, _ in
return .none
}
}
import UIKit
import SwiftUI
fileprivate struct ActivityViewController: UIViewControllerRepresentable {
var activityItems: [AnyObject]
var applicationActivities: [UIActivity]? = nil
func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityViewController>) -> UIActivityViewController {
UIActivityViewController(activityItems: activityItems, applicationActivities: applicationActivities)
}
func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<ActivityViewController>) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment