|
@@ -0,0 +1,234 @@
|
|
|
+//
|
|
|
+// ShareH5LinkView.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by 南鑫林 on 2019/10/11.
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+import Foundation
|
|
|
+
|
|
|
+import FWPopupView
|
|
|
+import RxSwift
|
|
|
+import SwiftyMediator
|
|
|
+
|
|
|
+
|
|
|
+class ShareH5LinkView: FWPopupView {
|
|
|
+
|
|
|
+ let disposeBag = DisposeBag()
|
|
|
+
|
|
|
+ let platformTitles = ["微信","朋友圈","QQ","微博","复制链接"]
|
|
|
+ let platformImages = ["edit_pic_wechat","edit_pic_moments","edit_pic_qq","edit_pic_sina","edit_pic_link"]
|
|
|
+
|
|
|
+ private var title : String?
|
|
|
+ private var detailTitle : String?
|
|
|
+ private var sharedTitle : String?
|
|
|
+ private var sharedDetailTitle : String?
|
|
|
+ private var h5Str : String?
|
|
|
+ private var thumbnailImg : UIImage?
|
|
|
+
|
|
|
+ override init(frame: CGRect) {
|
|
|
+ super.init(frame: frame)
|
|
|
+ }
|
|
|
+
|
|
|
+ typealias Completion = (() -> Void)
|
|
|
+ var completion : Completion?
|
|
|
+ init(title:String,detailTitle:String,h5Str:String,thumbnailImg:UIImage?,sharedTitle:String,sharedDetailTitle:String) {
|
|
|
+ self.init()
|
|
|
+ self.title = title
|
|
|
+ self.detailTitle = detailTitle
|
|
|
+ self.h5Str = h5Str
|
|
|
+ self.thumbnailImg = thumbnailImg
|
|
|
+ self.sharedTitle = sharedTitle
|
|
|
+ self.sharedDetailTitle = sharedDetailTitle
|
|
|
+ frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: 209 + kSafeTabBarHeight)
|
|
|
+ configRectCorner(corner: [.topLeft,.topRight], radii: CGSize(width: 8, height: 8))
|
|
|
+ setupViews()
|
|
|
+ setupLayouts()
|
|
|
+ setupData()
|
|
|
+ }
|
|
|
+
|
|
|
+ required init?(coder aDecoder: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
+
|
|
|
+ func setupViews() {
|
|
|
+ addSubview(titleLabel)
|
|
|
+ addSubview(detailTitleLabel)
|
|
|
+ addSubview(collectionView)
|
|
|
+ addSubview(lineLabel)
|
|
|
+ addSubview(cancelButton)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func setupLayouts() {
|
|
|
+ titleLabel.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(20)
|
|
|
+ make.right.equalTo(-20)
|
|
|
+ make.left.equalTo(20)
|
|
|
+ make.height.equalTo(18)
|
|
|
+ }
|
|
|
+ detailTitleLabel.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(titleLabel.snp.bottom).offset(10)
|
|
|
+ make.right.equalTo(-30)
|
|
|
+ make.left.equalTo(30)
|
|
|
+ make.height.equalTo(18)
|
|
|
+ }
|
|
|
+ collectionView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(detailTitleLabel.snp.bottom).offset(20)
|
|
|
+ make.height.equalTo(69)
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ }
|
|
|
+ lineLabel.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(collectionView.snp.bottom).offset(10)
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ make.height.equalTo(0.5)
|
|
|
+ }
|
|
|
+ cancelButton.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(lineLabel.snp.bottom)
|
|
|
+ make.height.equalTo(44)
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ lazy var titleLabel: UILabel = {
|
|
|
+ let titleLabel = UILabel()
|
|
|
+ titleLabel.text = title
|
|
|
+ titleLabel.textColor = k333333Color
|
|
|
+ titleLabel.font = kRegularFont15
|
|
|
+ titleLabel.textAlignment = .center
|
|
|
+ return titleLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var detailTitleLabel: UILabel = {
|
|
|
+ let detailTitleLabel = UILabel()
|
|
|
+ detailTitleLabel.text = detailTitle
|
|
|
+ detailTitleLabel.textColor = k333333Color
|
|
|
+ detailTitleLabel.font = kRegularFont15
|
|
|
+ detailTitleLabel.textAlignment = .center
|
|
|
+ return detailTitleLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var collectionView: UICollectionView = {
|
|
|
+ let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
|
|
|
+ collectionView.backgroundColor = UIColor.white
|
|
|
+ collectionView.delegate = self;
|
|
|
+ collectionView.dataSource = self;
|
|
|
+ collectionView.showsVerticalScrollIndicator = false
|
|
|
+ collectionView.showsHorizontalScrollIndicator = false
|
|
|
+ return collectionView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
|
+ let collectionViewLayout = UICollectionViewFlowLayout.init()
|
|
|
+ collectionViewLayout.minimumLineSpacing = 20
|
|
|
+ collectionViewLayout.minimumInteritemSpacing = 0
|
|
|
+ collectionViewLayout.scrollDirection = .horizontal
|
|
|
+ return collectionViewLayout
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var lineLabel: UILabel = {
|
|
|
+ let lineLabel = UILabel()
|
|
|
+ lineLabel.backgroundColor = kDDDDDDColor
|
|
|
+ return lineLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var cancelButton: UIButton = {
|
|
|
+ let cancelButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ cancelButton.setTitle("取消", for: UIControl.State.normal)
|
|
|
+ cancelButton.setTitleColor(k333333Color, for: UIControl.State.normal)
|
|
|
+ cancelButton.titleLabel?.font = kRegularFont16
|
|
|
+ return cancelButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ func setupData() {
|
|
|
+ cancelButton.rx.tap.subscribe(onNext: {
|
|
|
+ [weak self] _ in
|
|
|
+ self?.hide()
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// 分享内容
|
|
|
+ class func shareH5LinkView(title:String = kCommunityPostTitle,detailTitle:String = kCommunityPostDetailTitle, h5Str:String,thumbnailImg:UIImage?,sharedTitle:String,sharedDetailTitle:String,completion: @escaping Completion) {
|
|
|
+ let view = ShareH5LinkView(
|
|
|
+ title:title,
|
|
|
+ detailTitle: detailTitle,
|
|
|
+ h5Str: h5Str,
|
|
|
+ thumbnailImg : thumbnailImg,
|
|
|
+ sharedTitle: sharedTitle,
|
|
|
+ sharedDetailTitle:sharedDetailTitle)
|
|
|
+ view.completion = {
|
|
|
+ completion()
|
|
|
+ }
|
|
|
+ let vProperty = FWPopupViewProperty()
|
|
|
+ vProperty.popupCustomAlignment = .bottomCenter
|
|
|
+ vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
|
|
|
+ vProperty.popupAnimationType = .frame
|
|
|
+ vProperty.maskViewColor = UIColor(white: 0, alpha: 0.5)
|
|
|
+ vProperty.touchWildToHide = "1"
|
|
|
+ view.vProperty = vProperty
|
|
|
+ view.show()
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+extension ShareH5LinkView: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
|
|
|
+ func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
+ return 1
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
+ return platformTitles.count
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
+ let cell = ShareCommunityViewCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
|
|
|
+ cell.titleIcon(title: platformTitles[indexPath.row], iconStr: platformImages[indexPath.row], textColor: k333333Color)
|
|
|
+ return cell
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
+ switch indexPath.row {
|
|
|
+ case 0:
|
|
|
+ UMManager.shared.shareWebPage(to: UMSocialPlatformType.wechatSession, viewController: findViewController(), title: sharedTitle ?? "", descr: sharedDetailTitle ?? "", thumbImage: thumbnailImg as Any, webpageUrl: h5Str ?? "", completion: {
|
|
|
+ self.completion!()
|
|
|
+ })
|
|
|
+ break
|
|
|
+ case 1:
|
|
|
+ UMManager.shared.shareWebPage(to: UMSocialPlatformType.wechatTimeLine, viewController: findViewController(), title: sharedTitle ?? "", descr: sharedDetailTitle ?? "", thumbImage: thumbnailImg as Any, webpageUrl: h5Str ?? "",completion: {
|
|
|
+ self.completion!()
|
|
|
+ })
|
|
|
+
|
|
|
+ break
|
|
|
+ case 2:
|
|
|
+ UMManager.shared.shareWebPage(to: UMSocialPlatformType.QQ, viewController: findViewController(), title: sharedTitle ?? "", descr: sharedDetailTitle ?? "", thumbImage: thumbnailImg as Any, webpageUrl: h5Str ?? "",completion: {
|
|
|
+ self.completion!()
|
|
|
+ })
|
|
|
+
|
|
|
+ break
|
|
|
+ case 3:
|
|
|
+ UMManager.shared.shareWebPage(to: UMSocialPlatformType.sina, viewController: findViewController(), title: sharedTitle ?? "", descr: sharedDetailTitle ?? "", thumbImage: thumbnailImg as Any, webpageUrl: h5Str ?? "",completion: {
|
|
|
+ self.completion!()
|
|
|
+ })
|
|
|
+ break
|
|
|
+ case 4:
|
|
|
+ commonCopy(string: h5Str ?? "")
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ self.hide()
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
|
|
+ return CGSize(width:50, height: 69)
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
|
|
|
+ return UIEdgeInsets(top: 0, left: 23, bottom: 0, right: 23)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|