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
@State var selectedIndex: Int? = nil | |
let options: [String] = ["GraphQL", "Swift", "Vapor"] | |
var body: some View { | |
// ... | |
PickerField("Select an option", data: self.options, selectionIndex: self.$selectedIndex) | |
// ... | |
} |
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 | |
struct PickerField: UIViewRepresentable { | |
// MARK: - Public properties | |
@Binding var selectionIndex: Int? | |
// MARK: - Initializers | |
init<S>(_ title: S, data: [String], selectionIndex: Binding<Int?>) where S: StringProtocol { | |
self.placeholder = String(title) | |
self.data = data |
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 | |
class PickerTextField: UITextField { | |
// MARK: - Public properties | |
var data: [String] | |
@Binding var selectionIndex: Int? | |
// MARK: - Initializers | |
init(data: [String], selectionIndex: Binding<Int?>) { | |
self.data = data |
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
<script type="text/javascript"> | |
var _selector = document.querySelector('input[name=myCheckbox]'); | |
_selector.addEventListener('change', function(event) { | |
var message = (_selector.checked) ? "Toggle Switch is on" : "Toggle Switch is off"; | |
if (messageHandler) { | |
messageHandler.postMessage(message); | |
} | |
}); | |
</script> |
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
Widget buildWebView() { | |
return WebView( | |
. | |
. | |
. | |
javascriptChannels: <JavascriptChannel>{ | |
JavascriptChannel( | |
name: 'messageHandler', | |
onMessageReceived: (JavascriptMessage message) { | |
print("message from the web view=\"${message.message}\""); |
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
WebViewController? _webViewController; | |
Widget buildWebView() { | |
return WebView( | |
initialUrl: 'about:blank', | |
javascriptMode: JavascriptMode.unrestricted, | |
onWebViewCreated: (WebViewController webViewController) async { | |
_webViewController = webViewController; | |
String fileContent = await rootBundle.loadString('assets/index.html'); | |
_webViewController?.loadUrl(Uri.dataFromString(fileContent, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString()); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"/> | |
<style> | |
.switch { position: relative; display: inline-block; width: 60px; height: 34px; } | |
.switch input { opacity: 0; width: 0; height: 0; } | |
label.switch { outline: none; } | |
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; -webkit-transition: .4s; transition: .4s; outline: none; } | |
.slider:before { position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px; background-color: white; -webkit-transition: .4s; transition: .4s; } |
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 ArticlePage extends StatelessWidget { | |
final List<Section> sections; | |
const ArticlePage({Key? key, required this.sections}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
final tableOfContents = TableOfContents( | |
sections: sections, | |
onItemTap: (section) { |
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 TableOfContents extends StatelessWidget { | |
final List<Section> sections; | |
final void Function(Section) onItemTap; | |
const TableOfContents({ | |
Key? key, | |
this.sections = const <Section>[], | |
required this.onItemTap, | |
}) : super(key: key); |
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 SectionLink extends StatelessWidget { | |
final Section section; | |
final void Function(Section) onTap; | |
const SectionLink({Key? key, required this.section, required this.onTap}) | |
: super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return InkWell( |
NewerOlder