This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import UIKit | |
struct Result: Identifiable { | |
var id = UUID() | |
var value: String | |
} | |
class RefreshableObject: ObservableObject { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatefulWidget { | |
MyApp({Key key}) : super(key: key); | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
showDialog( | |
context: context, | |
builder: (BuildContext context) { | |
return AlertDialog( | |
title: Text("Title", textAlign: TextAlign.center), | |
content: Text("orem ipsum dolor sit amet, consectetur adipiscing elit. Aenean in congue nisi. Morbi tincidunt est id nibh dapibus, non pulvinar sem sollicitudin. Duis libero quam, posuere non justo non, facilisis sodales elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam sit amet dolor ut sem lobortis commodo id et nunc.",textAlign: TextAlign.center), | |
actions: <Widget>[ | |
FlatButton( | |
child: Text("This is veary long Text"), | |
onPressed: () { |