mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
Room timeline: Move files in explicit folders.
This commit is contained in:
@@ -0,0 +1,210 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Reusable
|
||||
|
||||
@objc
|
||||
protocol URLPreviewViewDelegate: AnyObject {
|
||||
func didOpenURLFromPreviewView(_ previewView: URLPreviewView, for eventID: String, in roomID: String)
|
||||
func didCloseURLPreviewView(_ previewView: URLPreviewView, for eventID: String, in roomID: String)
|
||||
}
|
||||
|
||||
@objcMembers
|
||||
/// A view to display `URLPreviewData` generated by the `URLPreviewManager`.
|
||||
class URLPreviewView: UIView, NibLoadable, Themable {
|
||||
// MARK: - Constants
|
||||
|
||||
private static let sizingView = URLPreviewView.instantiate()
|
||||
|
||||
private enum Constants {
|
||||
/// The fixed width of the preview view.
|
||||
static let width: CGFloat = 267.0
|
||||
/// A reduced width available for use on 4" devices.
|
||||
static let reducedWidth: CGFloat = 230
|
||||
|
||||
/// The availableWidth value that the XIB file is designed against.
|
||||
static let defaultAvailableWidth: CGFloat = 340
|
||||
/// The threshold value for available width that triggers the view to use a reducedWidth
|
||||
static let reducedWidthThreshold: CGFloat = 285
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
/// The preview data to display in the view.
|
||||
var preview: URLPreviewData? {
|
||||
didSet {
|
||||
guard let preview = preview else {
|
||||
renderLoading()
|
||||
return
|
||||
}
|
||||
renderLoaded(preview)
|
||||
}
|
||||
}
|
||||
|
||||
/// The total width available for the view to layout.
|
||||
/// Note: The view's width will be the largest `Constant` that fits this size.
|
||||
var availableWidth: CGFloat = Constants.defaultAvailableWidth {
|
||||
didSet {
|
||||
// TODO: adjust values when using RoomBubbleCellData's maxTextViewWidth property
|
||||
widthConstraint.constant = availableWidth <= Constants.reducedWidthThreshold ? Constants.reducedWidth : Constants.width
|
||||
}
|
||||
}
|
||||
|
||||
weak var delegate: URLPreviewViewDelegate?
|
||||
|
||||
@IBOutlet private weak var imageView: UIImageView!
|
||||
@IBOutlet private weak var closeButton: UIButton!
|
||||
|
||||
@IBOutlet private weak var textContainerView: UIView!
|
||||
@IBOutlet private weak var siteNameLabel: UILabel!
|
||||
@IBOutlet private weak var titleLabel: UILabel!
|
||||
@IBOutlet private weak var descriptionLabel: UILabel!
|
||||
|
||||
@IBOutlet private weak var loadingView: UIView!
|
||||
@IBOutlet private weak var loadingActivityIndicator: UIActivityIndicatorView!
|
||||
|
||||
// The constraint that determines the view's width
|
||||
@IBOutlet private weak var widthConstraint: NSLayoutConstraint!
|
||||
// Matches the label's height with the close button.
|
||||
// Use a strong reference to keep it around when deactivating.
|
||||
@IBOutlet private var siteNameLabelHeightConstraint: NSLayoutConstraint!
|
||||
|
||||
/// Returns true when `titleLabel` has a non-empty string.
|
||||
private var hasTitle: Bool {
|
||||
guard let title = titleLabel.text else { return false }
|
||||
return !title.isEmpty
|
||||
}
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
static func instantiate() -> Self {
|
||||
let view = Self.loadFromNib()
|
||||
view.update(theme: ThemeService.shared().theme)
|
||||
view.translatesAutoresizingMaskIntoConstraints = false // fixes unsatisfiable constraints encountered by the sizing view
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
// MARK: - Life cycle
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
layer.cornerRadius = 8
|
||||
layer.masksToBounds = true
|
||||
|
||||
imageView.contentMode = .scaleAspectFill
|
||||
|
||||
siteNameLabel.isUserInteractionEnabled = false
|
||||
titleLabel.isUserInteractionEnabled = false
|
||||
descriptionLabel.isUserInteractionEnabled = false
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func update(theme: Theme) {
|
||||
backgroundColor = theme.colors.navigation
|
||||
|
||||
siteNameLabel.textColor = theme.colors.secondaryContent
|
||||
siteNameLabel.font = theme.fonts.caption2SB
|
||||
|
||||
titleLabel.textColor = theme.colors.primaryContent
|
||||
titleLabel.font = theme.fonts.calloutSB
|
||||
|
||||
descriptionLabel.textColor = theme.colors.secondaryContent
|
||||
descriptionLabel.font = theme.fonts.caption1
|
||||
|
||||
let closeButtonAsset = ThemeService.shared().isCurrentThemeDark() ? Asset.Images.urlPreviewCloseDark : Asset.Images.urlPreviewClose
|
||||
closeButton.setImage(closeButtonAsset.image, for: .normal)
|
||||
}
|
||||
|
||||
static func contentViewHeight(for preview: URLPreviewData?, fitting maxWidth: CGFloat) -> CGFloat {
|
||||
sizingView.availableWidth = maxWidth
|
||||
sizingView.frame = CGRect(x: 0, y: 0, width: sizingView.widthConstraint.constant, height: 1)
|
||||
|
||||
// Call render directly to avoid storing the preview data in the sizing view
|
||||
if let preview = preview {
|
||||
sizingView.renderLoaded(preview)
|
||||
} else {
|
||||
sizingView.renderLoading()
|
||||
}
|
||||
|
||||
sizingView.setNeedsLayout()
|
||||
sizingView.layoutIfNeeded()
|
||||
|
||||
let fittingSize = CGSize(width: sizingView.widthConstraint.constant, height: UIView.layoutFittingCompressedSize.height)
|
||||
let layoutSize = sizingView.systemLayoutSizeFitting(fittingSize)
|
||||
|
||||
return layoutSize.height
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
/// Tells the view to show in it's loading state.
|
||||
private func renderLoading() {
|
||||
// hide the content
|
||||
imageView.isHidden = true
|
||||
textContainerView.isHidden = true
|
||||
|
||||
// show the loading interface
|
||||
loadingView.isHidden = false
|
||||
loadingActivityIndicator.startAnimating()
|
||||
}
|
||||
|
||||
/// Tells the view to display it's loaded state for the supplied data.
|
||||
private func renderLoaded(_ preview: URLPreviewData) {
|
||||
// update preview content
|
||||
imageView.image = preview.image
|
||||
siteNameLabel.text = preview.siteName ?? preview.url.host
|
||||
titleLabel.text = preview.title
|
||||
descriptionLabel.text = preview.text
|
||||
|
||||
// hide the loading interface
|
||||
loadingView.isHidden = true
|
||||
loadingActivityIndicator.stopAnimating()
|
||||
|
||||
// show the content
|
||||
textContainerView.isHidden = false
|
||||
|
||||
// tweak the layout depending on the content
|
||||
if imageView.image == nil {
|
||||
imageView.isHidden = true
|
||||
|
||||
siteNameLabelHeightConstraint.isActive = true
|
||||
descriptionLabel.numberOfLines = hasTitle ? 3 : 5
|
||||
} else {
|
||||
imageView.isHidden = false
|
||||
|
||||
siteNameLabelHeightConstraint.isActive = false
|
||||
descriptionLabel.numberOfLines = 2
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Action
|
||||
@IBAction private func openURL(_ sender: Any) {
|
||||
MXLog.debug("[URLPreviewView] Link was tapped.")
|
||||
guard let preview = preview else { return }
|
||||
|
||||
// Ask the delegate to open the URL for the event, as the bubble component
|
||||
// has the original un-sanitized URL that needs to be opened.
|
||||
delegate?.didOpenURLFromPreviewView(self, for: preview.eventID, in: preview.roomID)
|
||||
}
|
||||
|
||||
@IBAction private func close(_ sender: Any) {
|
||||
guard let preview = preview else { return }
|
||||
delegate?.didCloseURLPreviewView(self, for: preview.eventID, in: preview.roomID)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
|
||||
<device id="retina6_1" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
|
||||
<capability name="System colors in document resources" minToolsVersion="11.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<view contentMode="scaleToFill" id="dCz-KI-m5q" customClass="URLPreviewView" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="267" height="301"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="Rqc-iY-nm0">
|
||||
<rect key="frame" x="0.0" y="0.0" width="267" height="301"/>
|
||||
<subviews>
|
||||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="4zc-0W-jb8">
|
||||
<rect key="frame" x="0.0" y="0.0" width="267" height="140"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" secondItem="4zc-0W-jb8" secondAttribute="height" multiplier="267:140" id="0xq-yj-vni"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="n9x-Yn-0qQ" userLabel="Text Container">
|
||||
<rect key="frame" x="0.0" y="140" width="267" height="79"/>
|
||||
<subviews>
|
||||
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="2" translatesAutoresizingMaskIntoConstraints="NO" id="3Wa-hg-AAN">
|
||||
<rect key="frame" x="8" y="8" width="251" height="63"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Site Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ay6-fT-tTb">
|
||||
<rect key="frame" x="0.0" y="0.0" width="56" height="25"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="25" id="vhD-hz-f58"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="11"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IVX-5S-0kr">
|
||||
<rect key="frame" x="0.0" y="27" width="33.5" height="19.5"/>
|
||||
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="16"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" verticalCompressionResistancePriority="250" text="Description" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Z30-YF-eQk">
|
||||
<rect key="frame" x="0.0" y="48.5" width="65" height="14.5"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="12"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
</stackView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="3Wa-hg-AAN" secondAttribute="trailing" constant="8" id="2kO-tW-gxn"/>
|
||||
<constraint firstItem="3Wa-hg-AAN" firstAttribute="leading" secondItem="n9x-Yn-0qQ" secondAttribute="leading" constant="8" id="9gR-Ab-8qX"/>
|
||||
<constraint firstItem="3Wa-hg-AAN" firstAttribute="top" secondItem="n9x-Yn-0qQ" secondAttribute="top" constant="8" id="AJk-SF-ghk"/>
|
||||
<constraint firstAttribute="bottom" secondItem="3Wa-hg-AAN" secondAttribute="bottom" constant="8" id="ysy-Gi-EZT"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="u8r-SW-zAH">
|
||||
<rect key="frame" x="0.0" y="219" width="267" height="82"/>
|
||||
<subviews>
|
||||
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" style="medium" translatesAutoresizingMaskIntoConstraints="NO" id="SSJ-n0-24Z">
|
||||
<rect key="frame" x="123.5" y="32" width="20" height="18"/>
|
||||
</activityIndicatorView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstItem="SSJ-n0-24Z" firstAttribute="centerX" secondItem="u8r-SW-zAH" secondAttribute="centerX" id="121-oq-4Zn"/>
|
||||
<constraint firstAttribute="bottom" secondItem="SSJ-n0-24Z" secondAttribute="bottom" constant="32" id="1fW-21-XBI"/>
|
||||
<constraint firstItem="SSJ-n0-24Z" firstAttribute="top" secondItem="u8r-SW-zAH" secondAttribute="top" constant="32" id="9zi-Wb-6V5"/>
|
||||
<constraint firstItem="SSJ-n0-24Z" firstAttribute="centerY" secondItem="u8r-SW-zAH" secondAttribute="centerY" id="Puk-Mm-Vir"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="267" id="f2o-yq-NFO"/>
|
||||
</constraints>
|
||||
</stackView>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="30L-fe-CQa">
|
||||
<rect key="frame" x="227" y="0.0" width="40" height="40"/>
|
||||
<inset key="contentEdgeInsets" minX="8" minY="8" maxX="8" maxY="8"/>
|
||||
<state key="normal" image="url_preview_close"/>
|
||||
<connections>
|
||||
<action selector="close:" destination="dCz-KI-m5q" eventType="touchUpInside" id="Bh3-1r-Alc"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" systemColor="tertiarySystemFillColor"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="30L-fe-CQa" secondAttribute="trailing" id="3Vz-ER-W6l"/>
|
||||
<constraint firstItem="Rqc-iY-nm0" firstAttribute="top" secondItem="dCz-KI-m5q" secondAttribute="top" id="4yJ-eR-8oO"/>
|
||||
<constraint firstAttribute="trailing" secondItem="Rqc-iY-nm0" secondAttribute="trailing" id="AHA-th-scO"/>
|
||||
<constraint firstAttribute="bottom" secondItem="Rqc-iY-nm0" secondAttribute="bottom" id="NGE-IA-ky5"/>
|
||||
<constraint firstItem="Rqc-iY-nm0" firstAttribute="leading" secondItem="dCz-KI-m5q" secondAttribute="leading" id="jJ1-6i-YZj"/>
|
||||
<constraint firstItem="30L-fe-CQa" firstAttribute="top" secondItem="dCz-KI-m5q" secondAttribute="top" id="ydp-FM-Vv4"/>
|
||||
</constraints>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<connections>
|
||||
<outlet property="closeButton" destination="30L-fe-CQa" id="hFu-BX-zRP"/>
|
||||
<outlet property="descriptionLabel" destination="Z30-YF-eQk" id="DJ4-Bg-MHW"/>
|
||||
<outlet property="imageView" destination="4zc-0W-jb8" id="QRh-IX-XxR"/>
|
||||
<outlet property="loadingActivityIndicator" destination="SSJ-n0-24Z" id="ylX-Qd-8t5"/>
|
||||
<outlet property="loadingView" destination="u8r-SW-zAH" id="s7r-Kl-w5h"/>
|
||||
<outlet property="siteNameLabel" destination="ay6-fT-tTb" id="2wA-1z-lcs"/>
|
||||
<outlet property="siteNameLabelHeightConstraint" destination="vhD-hz-f58" id="Bz9-ub-9UA"/>
|
||||
<outlet property="textContainerView" destination="n9x-Yn-0qQ" id="Zul-rd-vrp"/>
|
||||
<outlet property="titleLabel" destination="IVX-5S-0kr" id="PRN-5g-HiO"/>
|
||||
<outlet property="widthConstraint" destination="f2o-yq-NFO" id="bn0-wB-66e"/>
|
||||
<outletCollection property="gestureRecognizers" destination="rSB-1V-Kev" appends="YES" id="OOJ-ft-VIj"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="1852.8985507246377" y="14.397321428571427"/>
|
||||
</view>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<tapGestureRecognizer id="rSB-1V-Kev">
|
||||
<connections>
|
||||
<action selector="openURL:" destination="dCz-KI-m5q" id="Fu6-Tb-bkW"/>
|
||||
</connections>
|
||||
</tapGestureRecognizer>
|
||||
</objects>
|
||||
<resources>
|
||||
<image name="url_preview_close" width="24" height="24"/>
|
||||
<systemColor name="tertiarySystemFillColor">
|
||||
<color red="0.46274509803921571" green="0.46274509803921571" blue="0.50196078431372548" alpha="0.12" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</systemColor>
|
||||
</resources>
|
||||
</document>
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the Lircense.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// `URLPreviewViewSizer` allows to determine reactions view height for a given urlPreviewData and width.
|
||||
class URLPreviewViewSizer {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private static let sizingView = URLPreviewView.instantiate()
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func height(for urlPreviewData: URLPreviewData, fittingWidth width: CGFloat) -> CGFloat {
|
||||
|
||||
let sizingView = URLPreviewViewSizer.sizingView
|
||||
|
||||
sizingView.frame.size.height = 1.0
|
||||
sizingView.preview = urlPreviewData
|
||||
sizingView.availableWidth = width
|
||||
|
||||
sizingView.setNeedsLayout()
|
||||
sizingView.layoutIfNeeded()
|
||||
|
||||
let fittingSize = CGSize(width: width, height: UIView.layoutFittingCompressedSize.height)
|
||||
|
||||
return sizingView.systemLayoutSizeFitting(fittingSize).height
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user