Skip to content

Instantly share code, notes, and snippets.

@pratikbutani
pratikbutani / PathUtils.java
Created September 9, 2019 05:53
Get Path from URI or URI from Path Utils.
public class PathUtils {
/**
* To get URI from Path
*
* @param context context
* @param file file
* @return Uri
*/
public static Uri getUriFromPath(Context context, File file) {
String filePath = file.getAbsolutePath();
@KanshuYokoo
KanshuYokoo / SwiftUIToastView.swift
Created April 2, 2020 11:44
SwiftuI ToastView example
import SwiftUI
struct ToastView: View {
@State private var liked: Bool = false
var body: some View {
VStack {
LikeButton(liked: $liked)
}
.toast(isShowing: $liked, text: Text("Hello toast!"))
@frankfka
frankfka / iOSCustomSegmentedControlSwiftUI.swift
Created May 17, 2020 16:47
Custom Segmented Picker / Segmented Control in SwiftUI
import SwiftUI
extension View {
func eraseToAnyView() -> AnyView {
AnyView(self)
}
}
struct SizePreferenceKey: PreferenceKey {
typealias Value = CGSize
@michaelevensen
michaelevensen / View+Geometry.swift
Last active November 13, 2023 12:20
A really handy extension to `View` which enables dynamic binding of `GeometryReader` properties like `Size`, `Frame` and `SafeAreaInsets` for a `View`. This is particularly handy when you want to share `GeometryReader` output between other `View`'s. All credit goes to @danielsaidi.
//
// View+Geometry.swift
// SwiftUIKit
//
// Created by Daniel Saidi on 2020-03-26.
// Copyright © 2020 Daniel Saidi. All rights reserved.
//
import SwiftUI
struct ExpandableButtonPanel: View {
let primaryItem: ExpandableButtonItem
let secondaryItems: [ExpandableButtonItem]
private let noop: () -> Void = {}
private let size: CGFloat = 70
private var cornerRadius: CGFloat {
get { size / 2 }
}
import SwiftUI
import Combine
public struct ChangeObserver<V: Equatable>: ViewModifier {
public init(newValue: V, action: @escaping (V) -> Void) {
self.newValue = newValue
self.newAction = action
}
private typealias Action = (V) -> Void
@kcochibili
kcochibili / BillingHolder.java
Last active November 16, 2022 03:50
Singleton class that fixes the issue with the android-inapp-billing-v3 library. This fix allows you to flawlessly use the BillingProcessor in multiple activities, without encountering this issue: https://github.com/anjlab/android-inapp-billing-v3/issues/503
package com.your.package.name;
import android.app.Activity;
import com.anjlab.android.iab.v3.BillingProcessor;
// This singleton class is designed to fix this issue: https://github.com/anjlab/android-inapp-billing-v3/issues/503
// the solution is based on this suggestion: https://github.com/anjlab/android-inapp-billing-v3/issues/501#issuecomment-962612355
public class BillingHolder {