Add show hide password button and delete unused SwiftUI extensions

This commit is contained in:
Maurice Parker
2019-10-21 13:44:47 -05:00
parent effec24674
commit ea267e80dd
10 changed files with 48 additions and 349 deletions

View File

@@ -1,45 +0,0 @@
//
// AttributedStringView.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 9/16/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI
struct AttributedStringView: UIViewRepresentable {
let string: NSAttributedString
let preferredMaxLayoutWidth: CGFloat
func makeUIView(context: Context) -> HackedTextView {
return HackedTextView()
}
func updateUIView(_ view: HackedTextView, context: Context) {
view.attributedText = string
view.preferredMaxLayoutWidth = preferredMaxLayoutWidth
view.isScrollEnabled = false
view.textContainer.lineBreakMode = .byWordWrapping
view.isUserInteractionEnabled = true
view.adjustsFontForContentSizeCategory = true
view.font = .preferredFont(forTextStyle: .body)
view.textColor = UIColor.label
view.tintColor = AppAssets.secondaryAccentColor
view.backgroundColor = UIColor.secondarySystemGroupedBackground
view.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
view.setContentCompressionResistancePriority(.required, for: .vertical)
}
}
class HackedTextView: UITextView {
var preferredMaxLayoutWidth = CGFloat.zero
override var intrinsicContentSize: CGSize {
return sizeThatFits(CGSize(width: preferredMaxLayoutWidth, height: .infinity))
}
}

View File

@@ -1,25 +0,0 @@
//
// PasswordField.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 10/8/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI
struct PasswordField: UIViewRepresentable {
let password: Binding<String>
func makeUIView(context: Context) -> ShowHidePasswordView {
let showHideView = Bundle.main.loadNibNamed("ShowHidePasswordView", owner: Self.self, options: nil)?[0] as! ShowHidePasswordView
showHideView.passwordTextField.bindingString = password
return showHideView
}
func updateUIView(_ showHideView: ShowHidePasswordView, context: Context) {
showHideView.passwordTextField.bindingString = password
}
}

View File

@@ -1,52 +0,0 @@
//
// SafariView.swift
// NetNewsWire-iOS
//
// Created by Stuart Breckenridge on 16/6/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI
import SafariServices
struct SafariView : UIViewControllerRepresentable {
let url: URL
func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController {
let safari = SFSafariViewController(url: url)
safari.delegate = context.coordinator
return safari
}
func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) {
//
}
func makeCoordinator() -> Coordinator {
return Coordinator(self)
}
class Coordinator : NSObject, SFSafariViewControllerDelegate {
var parent: SafariView
init(_ safariView: SafariView) {
self.parent = safariView
}
// MARK: SFSafariViewControllerDelegate
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
}
func safariViewController(_ controller: SFSafariViewController, initialLoadDidRedirectTo URL: URL) {
}
func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
}
}
}

View File

@@ -1,51 +0,0 @@
//
// ShowHidePasswordView.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 10/8/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
import SwiftUI
class ShowHidePasswordView: UIView {
@IBOutlet weak var passwordTextField: BindingTextField!
@IBOutlet weak var showHideButton: UIButton!
@IBAction func toggleShowHideButton(_ sender: Any) {
if passwordTextField.isSecureTextEntry {
passwordTextField.isSecureTextEntry = false
showHideButton.setTitle(NSLocalizedString("Hide", comment: "Hide"), for: .normal)
} else {
passwordTextField.isSecureTextEntry = true
showHideButton.setTitle(NSLocalizedString("Show", comment: "Show"), for: .normal)
}
}
}
class BindingTextField: UITextField, UITextFieldDelegate {
var bindingString: Binding<String>? = nil
override init(frame: CGRect) {
super.init(frame: frame)
delegate = self
}
required init?(coder: NSCoder) {
super.init(coder: coder)
delegate = self
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if let currentValue = textField.text as NSString? {
let proposedValue = currentValue.replacingCharacters(in: range, with: string)
bindingString?.wrappedValue = proposedValue
}
return true
}
}

View File

@@ -1,46 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15508"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="ShowHidePasswordView" customModule="NetNewsWire" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="284" height="54"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="TT2-5T-DdA">
<rect key="frame" x="246" y="12" width="38" height="30"/>
<state key="normal" title="Show"/>
<connections>
<action selector="toggleShowHideButton:" destination="iN0-l3-epB" eventType="touchUpInside" id="DTB-2f-JoB"/>
</connections>
</button>
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Password" textAlignment="natural" adjustsFontForContentSizeCategory="YES" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Iwe-LN-7ZI" customClass="BindingTextField" customModule="NetNewsWire" customModuleProvider="target">
<rect key="frame" x="0.0" y="16.5" width="238" height="21"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" secureTextEntry="YES"/>
</textField>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="TT2-5T-DdA" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="Buq-YS-fG8"/>
<constraint firstItem="TT2-5T-DdA" firstAttribute="leading" secondItem="Iwe-LN-7ZI" secondAttribute="trailing" constant="8" symbolic="YES" id="FIM-1x-LoT"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="TT2-5T-DdA" secondAttribute="trailing" id="b4w-k0-zUR"/>
<constraint firstItem="Iwe-LN-7ZI" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="eGg-IF-dp6"/>
<constraint firstItem="Iwe-LN-7ZI" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" id="mUI-zV-GHb"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<connections>
<outlet property="passwordTextField" destination="Iwe-LN-7ZI" id="Tvk-Q4-kHr"/>
<outlet property="showHideButton" destination="TT2-5T-DdA" id="1GH-1O-ma0"/>
</connections>
<point key="canvasLocation" x="43.478260869565219" y="-127.23214285714285"/>
</view>
</objects>
</document>

View File

@@ -1,25 +0,0 @@
//
// VibrantButtonStyle.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 9/16/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI
struct VibrantButtonStyle: ButtonStyle {
let alignment: Alignment
func makeBody(configuration: Configuration) -> some View {
GeometryReader { geometry in
configuration.label
.frame(width: geometry.size.width, height: geometry.size.height, alignment: self.alignment)
}
.foregroundColor(configuration.isPressed ? Color(AppAssets.tableViewCellHighlightedTextColor) : .primary)
.listRowBackground(configuration.isPressed ? Color(AppAssets.primaryAccentColor) : Color(.secondarySystemGroupedBackground))
.background(configuration.isPressed ? Color(AppAssets.primaryAccentColor) : Color(.secondarySystemGroupedBackground))
}
}

View File

@@ -1,40 +0,0 @@
//
// VibrantSelectAction.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 9/15/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI
struct VibrantSelectAction: ViewModifier {
let action: () -> Void
@State var isTapped = false
@GestureState var isLongPressed = false
func body(content: Content) -> some View {
GeometryReader { geometry in
content
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .leading)
.background(self.isLongPressed || self.isTapped ? Color(AppAssets.primaryAccentColor) : Color(.secondarySystemGroupedBackground))
}
.foregroundColor(isLongPressed || isTapped ? Color(AppAssets.tableViewCellHighlightedTextColor) : .primary)
.listRowBackground(isLongPressed || isTapped ? Color(AppAssets.primaryAccentColor) : nil)
.gesture(
LongPressGesture().onEnded( { _ in self.action() })
.updating($isLongPressed) { value, state, transcation in state = value }
.simultaneously(with:
TapGesture().onEnded( {
self.isTapped = true
self.action()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
self.isTapped = false
}
}
))
)
}
}