Skip to content

Instantly share code, notes, and snippets.

@ryanlintott
ryanlintott / NoClipText.swift
Last active August 20, 2021 02:40
Alternative Text view for SwiftUI with an extendable clipping area. This is a fix for certain fonts and characters that have a clipped intrinsic size.
import SwiftUI
import UIKit
struct NoClipText: UIViewRepresentable {
typealias UIViewType = NoClipLabel
let text: String
let font: UIFont
let clipExtension: EdgeSizes
extension UIHostingController {
convenience public init(rootView: Content, ignoreSafeArea: Bool) {
self.init(rootView: rootView)
if ignoreSafeArea {
disableSafeArea()
}
}
func disableSafeArea() {
import SwiftUI
import UIKit
extension Color {
var uiColor: UIColor {
if #available(iOS 14, *) {
// iOS 14 introduces an API to convert SwiftUI.Color to UIKit.UIColor
// but it does not produce a color which reacts to changes in color scheme
// (light mode/dark mode). To make that work we need to extract the color
@Jeehut
Jeehut / DurationFormat.kt
Last active October 1, 2023 14:39
Localized duration formatting in Kotlin using APIs in Android 9+ with fallback to English on Android 8 and lower.
import android.icu.text.MeasureFormat
import android.icu.text.NumberFormat
import android.icu.util.MeasureUnit
import android.os.Build
import java.util.Locale
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.days
import kotlin.time.hours
import kotlin.time.milliseconds
@HashNuke
HashNuke / SwiftUI-SplitView-MacOS.swift
Last active January 5, 2024 18:53
Using a NSSplitViewController with SwiftUI on mac to render SwiftUI views as split panes. Drop this code into a playground to try it out. SORRY MAC-OS ONLY. DOES NOT WORK ON IOS
import AppKit
import SwiftUI
// Delete this line if not using a playground
import PlaygroundSupport
struct ContentView: View {
var body: some View {
// if spacing is not set to zero, there will be a gap after the first row
@joshuabaker
joshuabaker / languages.json
Last active April 30, 2024 17:07
List of languages with ISO 639-1 Alpha-2 codes in JSON.
[
{
"code": "aa",
"name": "Afar",
"native": "Afar"
},
{
"code": "ab",
"name": "Abkhazian",
"native": "Аҧсуа"
@wtsnz
wtsnz / RemoteImage.swift
Created October 12, 2019 18:53
(Extremely) Basic way to load a remote image from URL in SwiftUI
import Combine
import SwiftUI
class RemoteImageLoader: ObservableObject {
@Published var data: Data = Data()
init(imageURL: URL) {
URLSession.shared.dataTask(with: imageURL) { data, response, error in
guard let data = data else { return }
@amelnychuck
amelnychuck / ExampleTabbedView.swift
Last active December 6, 2020 22:30
Example SwiftUI TabbedView Implementation (Xcode Beta 3)
import SwiftUI
struct ExampleTabbedView : View {
@State private var selection = 1
var body: some View {
TabbedView(selection: $selection) {
Text("Tab 1")
.tabItem({
@ivanbruel
ivanbruel / NetworkImage.swift
Last active August 16, 2021 06:28
Basic NetworkImage support for SwiftUI via Kingfisher
import SwiftUI
import Kingfisher
import UIKit
public struct NetworkImage: SwiftUI.View {
// swiftlint:disable:next redundant_optional_initialization
@State private var image: UIImage? = nil
public let imageURL: URL?
@slightfoot
slightfoot / always_scrollbar.dart
Created March 4, 2019 18:20
Always Visible Scrollbar for Flutter - 4th March 2019
import 'package:flutter/gestures.dart' show DragStartBehavior;
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.indigo,