Skip to content

Instantly share code, notes, and snippets.

class AdaptableText extends StatelessWidget {
final String text;
final TextStyle style;
final TextAlign textAlign;
final TextDirection textDirection;
final double minimumFontScale;
final TextOverflow textOverflow;
const AdaptableText(this.text,
{this.style,
this.textAlign = TextAlign.left,
import SwiftUI
import UIKit
struct Result: Identifiable {
var id = UUID()
var value: String
}
class RefreshableObject: ObservableObject {
import SwiftUI
import WebKit
struct ContentView: View {
@ObservedObject var webViewStateModel: WebViewStateModel = WebViewStateModel()
var body: some View {
NavigationView {
LoadingView(isShowing: .constant(webViewStateModel.loading)) { //loading logic taken from https://stackoverflow.com/a/56496896/9838937
//Add onNavigationAction if callback needed
struct ContentView: View {
@ObservedObject var webViewStateModel: WebViewStateModel = WebViewStateModel()
var body: some View {
NavigationView {
LoadingView(isShowing: .constant(webViewStateModel.loading)) { //loading logic taken from https://stackoverflow.com/a/56496896/9838937
//Add onNavigationAction if callback needed
WebView(url: URL.init(string: "https://www.google.com")!, webViewStateModel: self.webViewStateModel) // add
}
.navigationBarTitle(Text(webViewStateModel.pageTitle), displayMode: .inline)
class WebViewStateModel: ObservableObject {
@Published var pageTitle: String = "Web View"
@Published var loading: Bool = false
@Published var canGoBack: Bool = false
@Published var goBack: Bool = false
}
struct WebView: View {
enum NavigationAction {
case decidePolicy(WKNavigationAction, (WKNavigationActionPolicy) -> Void) //mendetory
final class WebViewWrapper : UIViewRepresentable {
...
final class Coordinator: NSObject {
@ObservedObject var webViewStateModel: WebViewStateModel
let action: ((_ navigationAction: WebView.NavigationAction) -> Void)?
init(action: ((_ navigationAction: WebView.NavigationAction) -> Void)?,
webViewStateModel: WebViewStateModel) {
self.action = action
self.webViewStateModel = webViewStateModel
final class WebViewWrapper : UIViewRepresentable {
@ObservedObject var webViewStateModel: WebViewStateModel //action two way binding
let action: ((_ navigationAction: WebView.NavigationAction) -> Void)? //delegates callback
let request: URLRequest
init(webViewStateModel: WebViewStateModel,
action: ((_ navigationAction: WebView.NavigationAction) -> Void)?,
request: URLRequest) {
self.action = action
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
void main() => runApp(MaterialApp( home: DemoApp()));
class DemoApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@prafullakumar
prafullakumar / AdaptsKeyboard.swift
Created April 16, 2020 15:08
Demo - Keyboard Animation with Form SwiftUI
import SwiftUI
import Combine
struct KeyboardProperty {
var currentHeight: CGFloat = 0
var animationDuration: Double = 0
//keyboard notification also gives UIKeyboardAnimationCurveUserInfoKey using which we can completly sync keyboard animation with Scrollview move but In SwiftUI I cannot find any way to use the same.
}
//
// ContentView.swift
// newUI
//
// Created by prafull kumar on 3/4/20.
// Copyright © 2020 prafull kumar. All rights reserved.
//
import SwiftUI