mattermost-mobile/ios/MattermostShare/Views/NavigationButtons/PostButton.swift
Elias Nahum 3a3123674a
[Gekidou] iOS Share extension (#6432)
* iOS Share extension

* Add Fastlane steps for iOS Share Extension

* new multi file layout

* Add recent label

* Refactor code & identation

* ux feedback

* downsample images

* remove options horizontal padding
2022-07-27 10:31:45 -04:00

54 lines
1.6 KiB
Swift

//
// PostButton.swift
// MattermostShare
//
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
//
import SwiftUI
struct PostButton: View {
@EnvironmentObject var shareViewModel: ShareViewModel
@Binding var attachments: [AttachmentModel]
var linkPreviewUrl: String
@Binding var message: String
@State var pressed: Bool = false
func submit() {
let userInfo: [String: Any] = [
"serverUrl": shareViewModel.server?.url as Any,
"channelId": shareViewModel.channel?.id as Any,
"attachments": attachments,
"linkPreviewUrl": linkPreviewUrl,
"message": message,
]
pressed = true
NotificationCenter.default.post(name: Notification.Name("doPost"), object: nil, userInfo: userInfo)
}
var body: some View {
let disabled =
shareViewModel.server == nil ||
shareViewModel.channel == nil ||
shareViewModel.allServers.count == 0 ||
!shareViewModel.server!.hasChannels ||
(message.isEmpty && linkPreviewUrl.isEmpty && attachments.isEmpty) ||
message.count > shareViewModel.server!.maxMessageLength ||
(attachments.count > 0 && shareViewModel.server!.uploadsDisabled) ||
attachments.contains {
($0.imagePixels ?? 0 > shareViewModel.server!.maxImageResolution) ||
($0.fileSize > shareViewModel.server!.maxFileSize)
}
FontIcon.button(
.compassIcons(code: .send),
action: submit,
fontsize: 24,
color: disabled || pressed ? .white.opacity(0.16) : .white
)
.padding(.leading, 10)
.padding(.vertical, 5)
.disabled(disabled || pressed)
}
}