Summary: This PR adds the example flipper plugin in swift sample app. Example flipper plugin acts as an example for the plugin authors. The example flipper plugin was already added in an objective c example but the swift sample app didn't have it. Pull Request resolved: https://github.com/facebook/flipper/pull/329 Reviewed By: jknoxville Differential Revision: D13085611 Pulled By: priteshrnandgaonkar fbshipit-source-id: d86cca43e95592ecca8d9991d170e62170b8217b
43 lines
1.3 KiB
Swift
43 lines
1.3 KiB
Swift
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
import UIKit
|
|
import FlipperKit
|
|
|
|
class CommunicationDemoViewController: UIViewController, UITableViewDataSource, FlipperKitExampleCommunicationResponderDelegate {
|
|
@IBOutlet weak var messageField: UITextField!
|
|
@IBOutlet weak var tableView: UITableView!
|
|
var messageArray: [String] = []
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
FlipperKitExamplePlugin.sharedInstance()?.delegate = self
|
|
}
|
|
|
|
@IBAction func tappedTriggerNotification(_ sender: UIButton) {
|
|
FlipperKitExamplePlugin.sharedInstance()?.triggerNotification();
|
|
}
|
|
|
|
@IBAction func tappedSendMessage(_ sender: UIButton) {
|
|
if let message = self.messageField.text {
|
|
FlipperKitExamplePlugin.sharedInstance()?.sendMessage(message);
|
|
}
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "reusableCell", for: indexPath)
|
|
cell.textLabel?.text = messageArray[indexPath.row]
|
|
return cell
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
return messageArray.count;
|
|
}
|
|
|
|
func messageReceived(_ msg: String!) {
|
|
messageArray.append(msg)
|
|
DispatchQueue.main.async { [weak self] in
|
|
self?.tableView.reloadData();
|
|
}
|
|
}
|
|
}
|