增加换肤功能
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// AlertTransitionAnimator.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2023/4/6.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class AlertTransitionAnimator : NSObject {
|
||||
enum AlertTransitionStyle {
|
||||
case present
|
||||
case dismiss
|
||||
}
|
||||
enum AlertTransitionPosition {
|
||||
case bottom
|
||||
case right
|
||||
}
|
||||
var duration = 0.5
|
||||
var alertTransitionStyle: AlertTransitionStyle = .present
|
||||
var alertTransitionPosition: AlertTransitionPosition = .bottom
|
||||
deinit {
|
||||
debugPrint("deinit \(self)")
|
||||
}
|
||||
}
|
||||
|
||||
extension AlertTransitionAnimator {
|
||||
private func presentTransition(transitionContext: UIViewControllerContextTransitioning) {
|
||||
guard let fromController = transitionContext.viewController(forKey: .from), let toController = transitionContext.viewController(forKey: .to)
|
||||
else { return }
|
||||
guard let fromView = fromController.view, let toView = toController.view else { return }
|
||||
let contentView = transitionContext.containerView
|
||||
fromView.tintAdjustmentMode = .normal
|
||||
fromView.isUserInteractionEnabled = false
|
||||
toView.isUserInteractionEnabled = false
|
||||
contentView.addSubview(toView)
|
||||
switch alertTransitionPosition {
|
||||
case .bottom:
|
||||
toView.frame = CGRect(x: 0, y: contentView.bounds.size.height, width: contentView.bounds.size.width, height:
|
||||
contentView.bounds.size.height)
|
||||
case .right:
|
||||
toView.frame = CGRect(x: contentView.bounds.size.width, y: 0, width: contentView.bounds.size.width/2, height:
|
||||
contentView.bounds.size.height)
|
||||
}
|
||||
UIView.animate(withDuration: duration, animations: { [weak self] in
|
||||
guard let self = self else { return }
|
||||
switch self.alertTransitionPosition {
|
||||
case .bottom:
|
||||
toView.frame = CGRect(x: 0, y: 0, width: contentView.bounds.size.width, height: contentView.bounds.size.height)
|
||||
case .right:
|
||||
toView.frame = CGRect(x: 0, y: 0, width: contentView.bounds.size.width, height: contentView.bounds.size.height)
|
||||
}
|
||||
}) { (finish) in
|
||||
fromView.isUserInteractionEnabled = true
|
||||
toView.isUserInteractionEnabled = true
|
||||
transitionContext.completeTransition(true)
|
||||
}
|
||||
}
|
||||
|
||||
private func dismissTransition(transitionContext: UIViewControllerContextTransitioning) {
|
||||
guard let fromController = transitionContext.viewController(forKey: .from), let toController = transitionContext.viewController(forKey: .to)
|
||||
else { return }
|
||||
guard let fromView = fromController.view, let toView = toController.view else { return }
|
||||
fromView.isUserInteractionEnabled = false
|
||||
toView.isUserInteractionEnabled = false
|
||||
let contentView = transitionContext.containerView
|
||||
UIView.animate(withDuration: duration, animations: { [weak self] in
|
||||
guard let self = self else { return }
|
||||
switch self.alertTransitionPosition {
|
||||
case .bottom:
|
||||
fromView.frame = CGRect(x: 0, y: contentView.bounds.size.height, width: contentView.bounds.size.width, height:
|
||||
contentView.bounds.size.height)
|
||||
case .right:
|
||||
fromView.frame = CGRect(x: contentView.bounds.size.width, y: 0, width: contentView.bounds.size.width, height:
|
||||
contentView.bounds.size.height)
|
||||
}
|
||||
}) { (finish) in
|
||||
fromView.removeFromSuperview()
|
||||
toView.isUserInteractionEnabled = true
|
||||
transitionContext.completeTransition(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension AlertTransitionAnimator: UIViewControllerAnimatedTransitioning {
|
||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||
return duration
|
||||
}
|
||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
switch alertTransitionStyle {
|
||||
case .present:
|
||||
presentTransition(transitionContext: transitionContext)
|
||||
case .dismiss:
|
||||
dismissTransition(transitionContext: transitionContext)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// BroadcastLauncher.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2023/1/17.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
import ReplayKit
|
||||
import UIKit
|
||||
|
||||
@available(iOS 12.0, *)
|
||||
class BroadcastLauncher: NSObject {
|
||||
var systemExtensionPicker = RPSystemBroadcastPickerView()
|
||||
var prevLaunchEventTime: CFTimeInterval = 0
|
||||
|
||||
static let sharedInstance = BroadcastLauncher()
|
||||
|
||||
override private init() {
|
||||
super.init()
|
||||
let picker = RPSystemBroadcastPickerView(frame: CGRect(x: 0, y: 0, width: 44, height: 44))
|
||||
picker.showsMicrophoneButton = false
|
||||
picker.autoresizingMask = [.flexibleTopMargin, .flexibleRightMargin]
|
||||
systemExtensionPicker = picker
|
||||
|
||||
if let pluginPath = Bundle.main.builtInPlugInsPath,
|
||||
let contents = try? FileManager.default.contentsOfDirectory(atPath: pluginPath) {
|
||||
for content in contents where content.hasSuffix(".appex") {
|
||||
guard let bundle = Bundle(path: URL(fileURLWithPath: pluginPath).appendingPathComponent(content).path),
|
||||
let identifier: String = (bundle.infoDictionary?["NSExtension"] as? [String: Any])? ["NSExtensionPointIdentifier"] as? String
|
||||
else {
|
||||
continue
|
||||
}
|
||||
if identifier == "com.apple.broadcast-services-upload" {
|
||||
picker.preferredExtension = bundle.bundleIdentifier
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func launch() {
|
||||
BroadcastLauncher.sharedInstance.launch()
|
||||
}
|
||||
|
||||
func launch() {
|
||||
let now = CFAbsoluteTimeGetCurrent()
|
||||
if now - prevLaunchEventTime < 1.0 {
|
||||
return
|
||||
}
|
||||
prevLaunchEventTime = now
|
||||
|
||||
for view in systemExtensionPicker.subviews {
|
||||
if let button = view as? UIButton {
|
||||
button.sendActions(for: .allTouchEvents)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
debugPrint("deinit \(self)")
|
||||
}
|
||||
}
|
||||
123
TUIKit/TUIRoomKit/Source/View/Component/ButtonItemView.swift
Normal file
123
TUIKit/TUIRoomKit/Source/View/Component/ButtonItemView.swift
Normal file
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// ButtonItemView.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2023/1/10.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class ButtonItemView: UIView {
|
||||
var itemData: ButtonItemData
|
||||
|
||||
lazy var controlButton: UIButton = {
|
||||
let button = UIButton()
|
||||
button.backgroundColor = itemData.backgroundColor
|
||||
if let cornerRadius = itemData.cornerRadius {
|
||||
button.layer.cornerRadius = cornerRadius
|
||||
}
|
||||
return button
|
||||
}()
|
||||
|
||||
lazy var label: UILabel = {
|
||||
let label = UILabel()
|
||||
label.textAlignment = isRTL ? .right : .left
|
||||
label.font = itemData.titleFont ?? UIFont(name: "PingFangSC-Regular", size: 14)
|
||||
label.textColor = itemData.titleColor ?? UIColor(0xD5E0F2)
|
||||
label.adjustsFontSizeToFitWidth = true
|
||||
return label
|
||||
}()
|
||||
|
||||
lazy var imageView: UIImageView = {
|
||||
let view = UIImageView()
|
||||
return view
|
||||
}()
|
||||
|
||||
lazy var lineView: UIView = {
|
||||
let view = UIView()
|
||||
view.backgroundColor = UIColor(0x4F586B,alpha: 0.1)
|
||||
view.isHidden = itemData.hasLineView ? false : true
|
||||
return view
|
||||
}()
|
||||
// MARK: - initialized function
|
||||
init(itemData: ButtonItemData) {
|
||||
self.itemData = itemData
|
||||
super.init(frame: .zero)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
// MARK: - view layout
|
||||
private var isViewReady: Bool = false
|
||||
override func didMoveToWindow() {
|
||||
super.didMoveToWindow()
|
||||
guard !isViewReady else { return }
|
||||
constructViewHierarchy()
|
||||
activateConstraints()
|
||||
bindInteraction()
|
||||
isViewReady = true
|
||||
}
|
||||
|
||||
func constructViewHierarchy() {
|
||||
addSubview(lineView)
|
||||
addSubview(controlButton)
|
||||
controlButton.addSubview(imageView)
|
||||
controlButton.addSubview(label)
|
||||
}
|
||||
|
||||
func activateConstraints() {
|
||||
controlButton.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
imageView.snp.makeConstraints { make in
|
||||
if let size = itemData.imageSize {
|
||||
make.size.equalTo(size)
|
||||
} else {
|
||||
make.width.height.equalTo(20)
|
||||
}
|
||||
if itemData.orientation == .left {
|
||||
make.leading.equalToSuperview()
|
||||
} else {
|
||||
make.trailing.equalToSuperview()
|
||||
}
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
label.snp.makeConstraints { make in
|
||||
make.centerY.equalToSuperview()
|
||||
if itemData.orientation == .left {
|
||||
make.leading.equalTo(imageView.snp.trailing).offset(10)
|
||||
} else {
|
||||
make.trailing.equalTo(imageView.snp.leading).offset(-10)
|
||||
}
|
||||
}
|
||||
lineView.snp.makeConstraints { make in
|
||||
make.bottom.equalToSuperview()
|
||||
make.leading.trailing.equalToSuperview()
|
||||
make.height.equalTo(1.scale375())
|
||||
}
|
||||
}
|
||||
|
||||
func bindInteraction() {
|
||||
setupViewState(item: itemData)
|
||||
controlButton.addTarget(self, action: #selector(clickMenuButton(sender:)), for: .touchUpInside)
|
||||
}
|
||||
|
||||
func setupViewState(item: ButtonItemData) {
|
||||
itemData = item
|
||||
controlButton.isSelected = item.isSelect
|
||||
controlButton.isEnabled = item.isEnabled
|
||||
imageView.image = item.isSelect ? itemData.selectedImage : itemData.normalImage
|
||||
label.text = item.isSelect ? itemData.selectedTitle : itemData.normalTitle
|
||||
}
|
||||
|
||||
@objc func clickMenuButton(sender: UIButton) {
|
||||
itemData.action?(sender)
|
||||
}
|
||||
|
||||
deinit {
|
||||
debugPrint("deinit \(self)")
|
||||
}
|
||||
}
|
||||
212
TUIKit/TUIRoomKit/Source/View/Component/ListCellItemView.swift
Normal file
212
TUIKit/TUIRoomKit/Source/View/Component/ListCellItemView.swift
Normal file
@@ -0,0 +1,212 @@
|
||||
//
|
||||
// ListCellItemView.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2023/1/6.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class ListCellItemView: UIView {
|
||||
let itemData: ListCellItemData
|
||||
|
||||
let titleLabel: UILabel = {
|
||||
let view = UILabel()
|
||||
view.backgroundColor = .clear
|
||||
view.textColor = UIColor(0x8F9AB2)
|
||||
view.font = UIFont(name: "PingFangSC-Medium", size: 14)
|
||||
view.minimumScaleFactor = 0.5
|
||||
return view
|
||||
}()
|
||||
|
||||
let messageLabel: UILabel = {
|
||||
let view = UILabel()
|
||||
view.backgroundColor = .clear
|
||||
view.textColor = UIColor(0xD5E0F2)
|
||||
view.font = UIFont(name: "PingFangSC-Medium", size: 14)
|
||||
view.adjustsFontSizeToFitWidth = false
|
||||
view.minimumScaleFactor = 0.5
|
||||
return view
|
||||
}()
|
||||
|
||||
let slider: UISlider = {
|
||||
let view = UISlider()
|
||||
return view
|
||||
}()
|
||||
|
||||
let sliderLabel: UILabel = {
|
||||
let view = UILabel()
|
||||
view.textAlignment = isRTL ? .left : .right
|
||||
view.backgroundColor = .clear
|
||||
view.textColor = UIColor(0xD1D9EC)
|
||||
view.font = UIFont(name: "PingFangSC-Medium", size: 14)
|
||||
view.adjustsFontSizeToFitWidth = true
|
||||
view.textAlignment = .center
|
||||
return view
|
||||
}()
|
||||
|
||||
let rightSwitch: UISwitch = {
|
||||
let view = UISwitch()
|
||||
view.isOn = true
|
||||
view.onTintColor = UIColor(0x0062E3)
|
||||
return view
|
||||
}()
|
||||
|
||||
lazy var rightButton: ButtonItemView = {
|
||||
let button = ButtonItemView(itemData: itemData.buttonData ?? ButtonItemData())
|
||||
return button
|
||||
}()
|
||||
|
||||
let downLineView : UIView = {
|
||||
let view = UIView()
|
||||
view.backgroundColor = UIColor(0x6B758A,alpha: 0.3)
|
||||
return view
|
||||
}()
|
||||
|
||||
init(itemData: ListCellItemData) {
|
||||
self.itemData = itemData
|
||||
super.init(frame: .zero)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
private var isViewReady: Bool = false
|
||||
override func didMoveToWindow() {
|
||||
super.didMoveToWindow()
|
||||
guard !isViewReady else { return }
|
||||
constructViewHierarchy()
|
||||
activateConstraints()
|
||||
bindInteraction()
|
||||
isViewReady = true
|
||||
}
|
||||
|
||||
func constructViewHierarchy() {
|
||||
addSubview(titleLabel)
|
||||
addSubview(messageLabel)
|
||||
addSubview(slider)
|
||||
addSubview(sliderLabel)
|
||||
addSubview(rightSwitch)
|
||||
addSubview(rightButton)
|
||||
addSubview(downLineView)
|
||||
}
|
||||
|
||||
func activateConstraints() {
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview()
|
||||
make.centerY.equalToSuperview()
|
||||
make.width.equalTo(100.scale375())
|
||||
make.height.equalTo(20.scale375())
|
||||
}
|
||||
|
||||
messageLabel.snp.makeConstraints { make in
|
||||
make.leading.equalTo(titleLabel.snp.trailing).offset(16.scale375())
|
||||
make.centerY.equalToSuperview()
|
||||
if itemData.hasRightButton {
|
||||
make.trailing.equalTo(rightButton.snp.leading)
|
||||
} else if (itemData.hasSwitch) {
|
||||
make.trailing.equalTo(rightSwitch.snp.leading)
|
||||
} else {
|
||||
make.trailing.equalToSuperview()
|
||||
}
|
||||
make.height.equalTo(20.scale375())
|
||||
}
|
||||
|
||||
slider.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview()
|
||||
make.width.equalTo(152.scale375())
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
|
||||
sliderLabel.snp.makeConstraints { make in
|
||||
make.leading.equalTo(titleLabel.snp.trailing).offset(5.scale375())
|
||||
make.trailing.equalTo(slider.snp.leading).offset(-5.scale375())
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
|
||||
rightSwitch.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview()
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
rightButton.snp.makeConstraints { make in
|
||||
make.centerY.equalToSuperview()
|
||||
make.trailing.equalToSuperview()
|
||||
if let size = itemData.buttonData?.size {
|
||||
make.width.equalTo(size.width)
|
||||
make.height.equalTo(size.height)
|
||||
} else {
|
||||
make.width.equalTo(57.scale375())
|
||||
make.height.equalTo(20.scale375Height())
|
||||
}
|
||||
}
|
||||
downLineView.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview()
|
||||
make.trailing.equalToSuperview()
|
||||
make.bottom.equalToSuperview()
|
||||
make.height.equalTo(0.5)
|
||||
}
|
||||
}
|
||||
|
||||
func bindInteraction() {
|
||||
setupViewState(item: itemData)
|
||||
if itemData.hasOverAllAction {
|
||||
let tap = UITapGestureRecognizer(target: self, action: #selector(overAllAction(sender:)))
|
||||
addGestureRecognizer(tap)
|
||||
}
|
||||
rightSwitch.addTarget(self, action: #selector(switchAction(sender:)), for: .touchUpInside)
|
||||
slider.addTarget(self, action: #selector(sliderAction(sender:)), for: .valueChanged)
|
||||
}
|
||||
|
||||
func setupViewState(item: ListCellItemData) {
|
||||
titleLabel.isHidden = item.titleText.isEmpty
|
||||
titleLabel.text = item.titleText
|
||||
if let titleColor = item.titleColor {
|
||||
titleLabel.textColor = titleColor
|
||||
}
|
||||
messageLabel.isHidden = item.messageText.isEmpty
|
||||
messageLabel.text = item.messageText
|
||||
if let messageColor = item.messageColor {
|
||||
messageLabel.textColor = messageColor
|
||||
}
|
||||
rightSwitch.isHidden = !item.hasSwitch
|
||||
rightSwitch.isOn = item.isSwitchOn
|
||||
rightButton.isHidden = !item.hasRightButton
|
||||
if let buttonData = item.buttonData {
|
||||
rightButton.setupViewState(item: buttonData)
|
||||
}
|
||||
slider.isHidden = !item.hasSlider
|
||||
sliderLabel.isHidden = !item.hasSliderLabel
|
||||
slider.minimumValue = item.minimumValue / item.sliderStep
|
||||
slider.maximumValue = item.maximumValue / item.sliderStep
|
||||
slider.value = item.sliderDefault / item.sliderStep
|
||||
sliderLabel.text = String(Int(slider.value) * Int(item.sliderStep)) + item.sliderUnit
|
||||
downLineView.isHidden = !itemData.hasDownLineView
|
||||
}
|
||||
|
||||
@objc func overAllAction(sender: UIView) {
|
||||
itemData.action?(sender)
|
||||
}
|
||||
|
||||
@objc func rightButtonAction(sender: UIButton) {
|
||||
itemData.action?(sender)
|
||||
}
|
||||
|
||||
@objc func switchAction(sender: UISwitch) {
|
||||
itemData.action?(sender)
|
||||
}
|
||||
|
||||
@objc func textFieldAction(sender: UITextField) {
|
||||
itemData.action?(sender)
|
||||
}
|
||||
|
||||
@objc func sliderAction(sender: UISlider) {
|
||||
sliderLabel.text = String(Int(slider.value) * Int(itemData.sliderStep)) + itemData.sliderUnit
|
||||
itemData.action?(sender)
|
||||
}
|
||||
|
||||
deinit {
|
||||
debugPrint("deinit \(self)")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
//
|
||||
// PrepareSettingItemView.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2023/1/6.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
class PrepareSettingItemView: UIView {
|
||||
let itemData: PrepareSettingItemData
|
||||
|
||||
let titleLabel: UILabel = {
|
||||
let view = UILabel()
|
||||
view.backgroundColor = .clear
|
||||
view.textColor = UIColor(0xD1D9EC)
|
||||
view.font = UIFont.systemFont(ofSize: 14, weight: .regular)
|
||||
view.minimumScaleFactor = 0.5
|
||||
return view
|
||||
}()
|
||||
|
||||
let messageLabel: UILabel = {
|
||||
let view = UILabel()
|
||||
view.backgroundColor = .clear
|
||||
view.textColor = UIColor(0xD1D9EC)
|
||||
view.font = UIFont.systemFont(ofSize: 14, weight: .medium)
|
||||
view.adjustsFontSizeToFitWidth = false
|
||||
view.numberOfLines = 0
|
||||
view.minimumScaleFactor = 0.5
|
||||
return view
|
||||
}()
|
||||
|
||||
let textField: UITextField = {
|
||||
let view = UITextField()
|
||||
view.backgroundColor = .clear
|
||||
view.textColor = UIColor(0xD1D9EC)
|
||||
view.font = UIFont(name: "PingFangSC-Regular", size: 14)
|
||||
let color = UIColor(0xBBBBBB)
|
||||
view.keyboardType = .numberPad
|
||||
return view
|
||||
}()
|
||||
|
||||
let rightSwitch: UISwitch = {
|
||||
let view = UISwitch()
|
||||
view.isOn = true
|
||||
view.onTintColor = UIColor(0x0062E3)
|
||||
return view
|
||||
}()
|
||||
|
||||
lazy var rightButton: UIButton = {
|
||||
let button = UIButton(type: .custom)
|
||||
let normalIcon = UIImage(named: "room_drop_down")
|
||||
button.setImage(normalIcon, for: .normal)
|
||||
return button
|
||||
}()
|
||||
|
||||
let downLineView : UIView = {
|
||||
let view = UIView()
|
||||
view.backgroundColor = UIColor(0x6B758A,alpha: 0.3)
|
||||
return view
|
||||
}()
|
||||
|
||||
init(itemData: PrepareSettingItemData) {
|
||||
self.itemData = itemData
|
||||
super.init(frame: .zero)
|
||||
self.setupViewState(item: itemData)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
private var isViewReady: Bool = false
|
||||
override func didMoveToWindow() {
|
||||
super.didMoveToWindow()
|
||||
guard !isViewReady else { return }
|
||||
constructViewHierarchy()
|
||||
activateConstraints()
|
||||
bindInteraction()
|
||||
isViewReady = true
|
||||
}
|
||||
|
||||
private func constructViewHierarchy() {
|
||||
addSubview(titleLabel)
|
||||
addSubview(messageLabel)
|
||||
addSubview(textField)
|
||||
addSubview(rightSwitch)
|
||||
addSubview(rightButton)
|
||||
addSubview(downLineView)
|
||||
}
|
||||
|
||||
private func activateConstraints() {
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview().offset(20)
|
||||
make.centerY.equalToSuperview()
|
||||
make.width.equalTo(100.scale375())
|
||||
}
|
||||
|
||||
messageLabel.snp.makeConstraints { make in
|
||||
make.left.equalTo(titleLabel.snp.right).offset(10.scale375())
|
||||
make.trailing.equalToSuperview().offset(-40)
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
|
||||
textField.snp.makeConstraints { make in
|
||||
make.left.equalTo(titleLabel.snp.right).offset(10)
|
||||
make.trailing.equalToSuperview().offset(-100)
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
|
||||
rightSwitch.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().offset(-20)
|
||||
make.centerY.equalToSuperview()
|
||||
make.width.equalTo(42)
|
||||
make.height.equalTo(24)
|
||||
}
|
||||
|
||||
rightButton.snp.makeConstraints { make in
|
||||
make.centerY.equalToSuperview()
|
||||
make.trailing.equalToSuperview().offset(-20)
|
||||
}
|
||||
|
||||
downLineView.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview().offset(20)
|
||||
make.trailing.equalToSuperview().offset(-20)
|
||||
make.bottom.equalToSuperview()
|
||||
make.height.equalTo(1)
|
||||
}
|
||||
}
|
||||
|
||||
private func bindInteraction() {
|
||||
if itemData.hasOverAllAction {
|
||||
let tap = UITapGestureRecognizer(target: self, action: #selector(overAllAction(sender:)))
|
||||
addGestureRecognizer(tap)
|
||||
}
|
||||
rightButton.addTarget(self, action: #selector(rightButtonAction(sender:)), for: .touchUpInside)
|
||||
rightSwitch.addTarget(self, action: #selector(switchAction(sender:)), for: .touchUpInside)
|
||||
}
|
||||
|
||||
func setupViewState(item: PrepareSettingItemData) {
|
||||
if item.titleText.isEmpty {
|
||||
titleLabel.isHidden = true
|
||||
}
|
||||
if item.messageText.isEmpty {
|
||||
messageLabel.isHidden = true
|
||||
}
|
||||
if !item.hasFieldView {
|
||||
textField.isHidden = true
|
||||
}
|
||||
if !item.hasSwitch {
|
||||
rightSwitch.isHidden = true
|
||||
}
|
||||
if !item.hasButton {
|
||||
rightButton.isHidden = true
|
||||
}
|
||||
rightSwitch.isOn = item.isSwitchOn
|
||||
titleLabel.text = item.titleText
|
||||
messageLabel.text = item.messageText
|
||||
textField.isUserInteractionEnabled = item.fieldEnable
|
||||
textField.delegate = self
|
||||
if item.fieldEnable {
|
||||
let color = UIColor(0xBBBBBB)
|
||||
textField.attributedPlaceholder = NSAttributedString(string: item.fieldPlaceholderText,attributes:
|
||||
[NSAttributedString.Key.foregroundColor:color])
|
||||
} else {
|
||||
textField.text = item.fieldText
|
||||
}
|
||||
downLineView.isHidden = !item.hasDownLineView
|
||||
}
|
||||
|
||||
@objc func overAllAction(sender: UIView) {
|
||||
itemData.action?(sender)
|
||||
}
|
||||
|
||||
@objc func rightButtonAction(sender: UIButton) {
|
||||
itemData.action?(sender)
|
||||
}
|
||||
|
||||
@objc func switchAction(sender: UISwitch) {
|
||||
itemData.action?(sender)
|
||||
}
|
||||
|
||||
@objc func textFieldAction(sender: UITextField) {
|
||||
itemData.action?(sender)
|
||||
}
|
||||
|
||||
deinit {
|
||||
debugPrint("deinit \(self)")
|
||||
}
|
||||
}
|
||||
|
||||
extension PrepareSettingItemView: UITextFieldDelegate {
|
||||
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
||||
let maxCount = 11
|
||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.05) {
|
||||
textField.text = textField.text?
|
||||
.replacingOccurrences(of: " ",
|
||||
with: "",
|
||||
options: .literal,
|
||||
range: nil)
|
||||
.addIntervalSpace(intervalStr: " ", interval: 3)
|
||||
}
|
||||
|
||||
guard let textFieldText = textField.text,
|
||||
let rangeOfTextToReplace = Range(range, in: textFieldText) else {
|
||||
return false
|
||||
}
|
||||
let substringToReplace = textFieldText[rangeOfTextToReplace]
|
||||
if substringToReplace.count > 0 && string.count == 0 {
|
||||
return true
|
||||
}
|
||||
let count = textFieldText.count - substringToReplace.count + string.count
|
||||
|
||||
let res = count <= maxCount
|
||||
return res
|
||||
}
|
||||
|
||||
func textFieldDidChangeSelection(_ textField: UITextField) {
|
||||
textFieldAction(sender: textField)
|
||||
}
|
||||
|
||||
func textFieldDidEndEditing(_ textField: UITextField) {
|
||||
textFieldAction(sender: textField)
|
||||
}
|
||||
}
|
||||
249
TUIKit/TUIRoomKit/Source/View/Component/QRCodeView.swift
Normal file
249
TUIKit/TUIRoomKit/Source/View/Component/QRCodeView.swift
Normal file
@@ -0,0 +1,249 @@
|
||||
//
|
||||
// QRCodeView.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2023/1/11.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class QRCodeView: UIView {
|
||||
let viewModel: QRCodeViewModel
|
||||
|
||||
let backButton: UIButton = {
|
||||
let button = UIButton()
|
||||
button.contentVerticalAlignment = .center
|
||||
button.contentHorizontalAlignment = isRTL ? .right : .left
|
||||
button.setTitleColor(UIColor(0xADB6CC), for: .normal)
|
||||
let image = UIImage(named: "room_back_white", in: tuiRoomKitBundle(), compatibleWith: nil)?.checkOverturn()
|
||||
button.setImage(image, for: .normal)
|
||||
button.titleLabel?.font = UIFont(name: "PingFangSC-Regular", size: 18)
|
||||
button.titleEdgeInsets = UIEdgeInsets(top: 0, left: 25, bottom: 0, right: 0)
|
||||
button.imageEdgeInsets = UIEdgeInsets(top: 0, left: 12, bottom: 0, right: 0)
|
||||
return button
|
||||
}()
|
||||
|
||||
let middleView: UIView = {
|
||||
let view = UIView()
|
||||
view.backgroundColor = UIColor(0x2A2D38)
|
||||
return view
|
||||
}()
|
||||
|
||||
let titleLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
label.textColor = UIColor(0xD1D9EC)
|
||||
label.font = UIFont(name: "PingFangSC-Regular", size: 28)
|
||||
label.textAlignment = .center
|
||||
label.backgroundColor = .clear
|
||||
label.adjustsFontSizeToFitWidth = true
|
||||
return label
|
||||
}()
|
||||
|
||||
let roomIdView: UIView = {
|
||||
let view = UIView()
|
||||
view.backgroundColor = .clear
|
||||
return view
|
||||
}()
|
||||
|
||||
let roomIdLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
label.textColor = UIColor(0xD1D9EC)
|
||||
label.font = UIFont(name: "PingFangSC-Regular", size: 20)
|
||||
label.adjustsFontSizeToFitWidth = true
|
||||
label.textAlignment = .center
|
||||
return label
|
||||
}()
|
||||
|
||||
let copyButton: UIButton = {
|
||||
let button = UIButton()
|
||||
let normalIcon = UIImage(named: "room_copy", in: tuiRoomKitBundle(), compatibleWith: nil)
|
||||
button.setImage(normalIcon, for: .normal)
|
||||
return button
|
||||
}()
|
||||
|
||||
let qrCodeView: UIView = {
|
||||
let view = UIView()
|
||||
view.backgroundColor = .white
|
||||
return view
|
||||
}()
|
||||
|
||||
let qrCodeImageView: UIImageView = {
|
||||
let imageView = UIImageView()
|
||||
return imageView
|
||||
}()
|
||||
|
||||
let qrCodeLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
label.textColor = .black
|
||||
label.text = .scanCodeText
|
||||
label.textAlignment = .center
|
||||
return label
|
||||
}()
|
||||
|
||||
let tencentImageView: UIImageView = {
|
||||
let image = UIImage(named: "room_tencent", in: tuiRoomKitBundle(), compatibleWith: nil)
|
||||
let imageView = UIImageView(image: image)
|
||||
return imageView
|
||||
}()
|
||||
|
||||
let bottomButton: UIButton = {
|
||||
let button = UIButton()
|
||||
button.backgroundColor = UIColor(0x006CFF)
|
||||
button.setTitle(.saveIntoAlbumText, for: .normal)
|
||||
button.backgroundColor = UIColor(0x006CFF)
|
||||
button.setTitleColor(.white, for: .normal)
|
||||
return button
|
||||
}()
|
||||
|
||||
init(viewModel: QRCodeViewModel) {
|
||||
self.viewModel = viewModel
|
||||
super.init(frame: .zero)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
private var isViewReady: Bool = false
|
||||
override func didMoveToWindow() {
|
||||
super.didMoveToWindow()
|
||||
guard !isViewReady else { return }
|
||||
constructViewHierarchy()
|
||||
activateConstraints()
|
||||
bindInteraction()
|
||||
isViewReady = true
|
||||
}
|
||||
|
||||
override func draw(_ rect: CGRect) {
|
||||
super.draw(rect)
|
||||
middleView.roundedRect(rect: middleView.bounds,
|
||||
byRoundingCorners: [.topLeft, .topRight, .bottomLeft, .bottomRight],
|
||||
cornerRadii: CGSize(width: 12, height: 12))
|
||||
qrCodeView.roundedRect(rect: qrCodeView.bounds,
|
||||
byRoundingCorners: [.topLeft, .topRight, .bottomLeft, .bottomRight],
|
||||
cornerRadii: CGSize(width: 12, height: 12))
|
||||
bottomButton.roundedRect(rect: bottomButton.bounds,
|
||||
byRoundingCorners: [.topLeft, .topRight, .bottomLeft, .bottomRight],
|
||||
cornerRadii: CGSize(width: 12, height: 12))
|
||||
}
|
||||
|
||||
func constructViewHierarchy() {
|
||||
addSubview(backButton)
|
||||
addSubview(middleView)
|
||||
addSubview(bottomButton)
|
||||
middleView.addSubview(titleLabel)
|
||||
middleView.addSubview(roomIdView)
|
||||
middleView.addSubview(qrCodeView)
|
||||
middleView.addSubview(tencentImageView)
|
||||
roomIdView.addSubview(roomIdLabel)
|
||||
roomIdView.addSubview(copyButton)
|
||||
qrCodeView.addSubview(qrCodeImageView)
|
||||
qrCodeView.addSubview(qrCodeLabel)
|
||||
}
|
||||
|
||||
func activateConstraints() {
|
||||
backButton.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview()
|
||||
make.top.equalTo(safeAreaLayoutGuide.snp.top)
|
||||
make.height.equalTo(20)
|
||||
make.width.equalTo(200)
|
||||
}
|
||||
middleView.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview().offset(12.scale375())
|
||||
make.trailing.equalToSuperview().offset(-12.scale375())
|
||||
make.height.equalTo(399.scale375())
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(24.scale375())
|
||||
make.height.equalTo(30.scale375())
|
||||
make.width.equalToSuperview()
|
||||
}
|
||||
roomIdView.snp.makeConstraints { make in
|
||||
make.top.equalTo(titleLabel.snp.bottom).offset(4.scale375())
|
||||
make.width.equalTo(120.scale375())
|
||||
make.centerX.equalToSuperview()
|
||||
make.height.equalTo(22.scale375())
|
||||
}
|
||||
roomIdLabel.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview()
|
||||
make.height.equalToSuperview()
|
||||
make.width.equalTo(80.scale375())
|
||||
}
|
||||
copyButton.snp.makeConstraints { make in
|
||||
make.leading.equalTo(roomIdLabel.snp.trailing).offset(3)
|
||||
make.centerY.equalToSuperview()
|
||||
make.width.height.equalTo(22.scale375())
|
||||
}
|
||||
qrCodeView.snp.makeConstraints { make in
|
||||
make.top.equalTo(roomIdView.snp.bottom).offset(10)
|
||||
make.centerX.equalToSuperview()
|
||||
make.width.equalTo(210.scale375())
|
||||
make.height.equalTo(242.scale375())
|
||||
}
|
||||
qrCodeImageView.snp.makeConstraints { make in
|
||||
make.width.height.equalTo(162.scale375())
|
||||
make.top.equalToSuperview().offset(24.scale375())
|
||||
make.centerX.equalToSuperview()
|
||||
}
|
||||
qrCodeLabel.snp.makeConstraints { make in
|
||||
make.width.equalToSuperview()
|
||||
make.height.equalTo(20.scale375())
|
||||
make.top.equalTo(qrCodeImageView.snp.bottom).offset(24.scale375())
|
||||
}
|
||||
tencentImageView.snp.makeConstraints { make in
|
||||
make.top.equalTo(qrCodeView.snp.bottom).offset(20.scale375())
|
||||
make.centerX.equalToSuperview()
|
||||
make.width.equalTo(86.scale375())
|
||||
make.height.equalTo(23.scale375())
|
||||
}
|
||||
bottomButton.snp.makeConstraints { make in
|
||||
make.width.equalTo(200.scale375())
|
||||
make.height.equalTo(52.scale375())
|
||||
make.centerX.equalToSuperview()
|
||||
make.bottom.equalToSuperview().offset(-30.scale375())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func bindInteraction() {
|
||||
setupViewState()
|
||||
backButton.addTarget(self, action: #selector(backAction(sender:)), for: .touchUpInside)
|
||||
copyButton.addTarget(self, action: #selector(copyAction(sender:)), for: .touchUpInside)
|
||||
bottomButton.addTarget(self, action: #selector(saveIntoAlbumAction(sender:)), for: .touchUpInside)
|
||||
}
|
||||
|
||||
func setupViewState() {
|
||||
backgroundColor = UIColor(0x17181F)
|
||||
titleLabel.text = viewModel.store.roomInfo.name
|
||||
roomIdLabel.text = viewModel.store.roomInfo.roomId
|
||||
viewModel.createQRCodeImageView(url: viewModel.urlString, imageView: qrCodeImageView)
|
||||
}
|
||||
|
||||
@objc func backAction(sender: UIButton) {
|
||||
viewModel.backAction()
|
||||
}
|
||||
|
||||
@objc func copyAction(sender: UIButton) {
|
||||
viewModel.copyAction(sender: sender, text: roomIdLabel.text ?? "")
|
||||
}
|
||||
|
||||
@objc func saveIntoAlbumAction(sender: UIButton) {
|
||||
guard let image = qrCodeImageView.image else { return }
|
||||
viewModel.saveIntoAlbumAction(sender: sender, image: image)
|
||||
}
|
||||
|
||||
deinit {
|
||||
debugPrint("deinit \(self)")
|
||||
}
|
||||
}
|
||||
|
||||
private extension String {
|
||||
static var scanCodeText: String {
|
||||
localized("Scan the code to enter the conference")
|
||||
}
|
||||
static var saveIntoAlbumText: String {
|
||||
localized("Save into the album")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// RoomKitNavigationController.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2023/4/20.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class RoomKitNavigationController: UINavigationController {
|
||||
override init(rootViewController: UIViewController) {
|
||||
super.init(rootViewController: rootViewController)
|
||||
interactivePopGestureRecognizer?.isEnabled = false
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
}
|
||||
|
||||
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
||||
guard let supportedInterfaceOrientations = topViewController?.supportedInterfaceOrientations as? UIInterfaceOrientationMask
|
||||
else { return .portrait }
|
||||
return supportedInterfaceOrientations
|
||||
}
|
||||
override var shouldAutorotate: Bool {
|
||||
guard let shouldAutorotate = topViewController?.shouldAutorotate else { return false }
|
||||
return shouldAutorotate
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user