Added custom swift plugin
Summary: Our very own SeaMammal plugin for iOS written in swift Reviewed By: passy Differential Revision: D15199381 fbshipit-source-id: 10b085c314328ff52ae3f5feef51f70d0ce12f1b
This commit is contained in:
committed by
Facebook Github Bot
parent
a8e7f0e028
commit
b1be6400b8
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import FlipperKit
|
||||
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
@@ -16,6 +17,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
let client = FlipperClient.shared()
|
||||
let layoutDescriptorMapper = SKDescriptorMapper(defaults: ())
|
||||
// If you want to debug componentkit view in swift, otherwise you can omit the next line
|
||||
FlipperKitLayoutComponentKitSupport.setUpWith(layoutDescriptorMapper)
|
||||
client?.add(FlipperKitLayoutPlugin(rootNode: application, with: layoutDescriptorMapper!))
|
||||
client?.add(FlipperKitNetworkPlugin(networkAdapter: SKIOSNetworkAdapter()))
|
||||
client?.add(FKUserDefaultsPlugin.init(suiteName: nil))
|
||||
client?.add(SeaMammalsPlugin(MarineMammal.defaultList))
|
||||
client?.start()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,12 @@ import UIKit
|
||||
struct MarineMammal {
|
||||
let name: String
|
||||
let image: URL
|
||||
static let defaultList: [MarineMammal] = [
|
||||
MarineMammal(name: "Polar Bear", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Ursus_maritimus_4_1996-08-04.jpg/190px-Ursus_maritimus_4_1996-08-04.jpg")!),
|
||||
MarineMammal(name: "Sea Otter", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Sea_otter_cropped.jpg/220px-Sea_otter_cropped.jpg")!),
|
||||
MarineMammal(name: "West Indian Manatee", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/FL_fig04.jpg/230px-FL_fig04.jpg")!),
|
||||
MarineMammal(name: "Bottlenose Dolphin", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Tursiops_truncatus_01.jpg/220px-Tursiops_truncatus_01.jpg")!),
|
||||
]
|
||||
}
|
||||
|
||||
class MarineMammalCell: UITableViewCell {
|
||||
|
||||
34
iOS/Tutorial/Tutorial/SeaMammalsPlugin.swift
Normal file
34
iOS/Tutorial/Tutorial/SeaMammalsPlugin.swift
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// MyFlipperPlugin.swift
|
||||
// Tutorial
|
||||
//
|
||||
// Created by Pritesh Nandgaonkar on 5/3/19.
|
||||
// Copyright © 2019 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import FlipperKit
|
||||
|
||||
class SeaMammalsPlugin: NSObject, FlipperPlugin {
|
||||
var connection: FlipperConnection? = nil
|
||||
let mammals: [MarineMammal]
|
||||
|
||||
init(_ marineMammals: [MarineMammal]) {
|
||||
mammals = marineMammals
|
||||
}
|
||||
|
||||
func identifier() -> String! {
|
||||
return "sea-mammals"
|
||||
}
|
||||
|
||||
func didConnect(_ connection: FlipperConnection!) {
|
||||
self.connection = connection
|
||||
for (index, mammal) in mammals.enumerated() {
|
||||
connection.send("newRow", withParams: ["id": index, "title": mammal.name, "url": mammal.image.absoluteString])
|
||||
}
|
||||
}
|
||||
|
||||
func didDisconnect() {
|
||||
connection = nil;
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,7 @@
|
||||
import UIKit
|
||||
|
||||
class ViewController: UIViewController, UITableViewDataSource {
|
||||
let marineMammals: [MarineMammal] = [
|
||||
MarineMammal(name: "Polar Bear", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Ursus_maritimus_4_1996-08-04.jpg/190px-Ursus_maritimus_4_1996-08-04.jpg")!),
|
||||
MarineMammal(name: "Sea Otter", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Sea_otter_cropped.jpg/220px-Sea_otter_cropped.jpg")!),
|
||||
MarineMammal(name: "West Indian Manatee", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/FL_fig04.jpg/230px-FL_fig04.jpg")!),
|
||||
MarineMammal(name: "Bottlenose Dolphin", image: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Tursiops_truncatus_01.jpg/220px-Tursiops_truncatus_01.jpg")!),
|
||||
]
|
||||
let marineMammals: [MarineMammal] = MarineMammal.defaultList
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
|
||||
Reference in New Issue
Block a user