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
60
iOS/Tutorial/Podfile
Normal file
60
iOS/Tutorial/Podfile
Normal file
@@ -0,0 +1,60 @@
|
||||
project 'Tutorial.xcodeproj'
|
||||
swift_version = "4.1"
|
||||
flipperkit_version = '0.20.0'
|
||||
use_frameworks!
|
||||
|
||||
target 'Tutorial' do
|
||||
platform :ios, '9.0'
|
||||
|
||||
pod 'FlipperKit', '~>' + flipperkit_version
|
||||
# Layout and network plugins are not yet supported for swift projects
|
||||
pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', '~>' + flipperkit_version
|
||||
pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version
|
||||
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version
|
||||
|
||||
# If you use `use_frameworks!` in your Podfile,
|
||||
# uncomment the below $static_framework array and also
|
||||
# the pre_install section. This will cause Flipper and
|
||||
# it's dependencies to be static and all other pods to
|
||||
# be dynamic.
|
||||
|
||||
$static_framework = ['FlipperKit', 'Flipper', 'Flipper-Folly',
|
||||
'CocoaAsyncSocket', 'ComponentKit', 'DoubleConversion',
|
||||
'glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit',
|
||||
'CocoaLibEvent', 'OpenSSL-Static', 'boost-for-react-native']
|
||||
|
||||
pre_install do |installer|
|
||||
Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
|
||||
installer.pod_targets.each do |pod|
|
||||
if $static_framework.include?(pod.name)
|
||||
pod.instance_variable_set(:@host_requires_frameworks, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# This post_install hook adds the -DFB_SONARKIT_ENABLED flag to OTHER_SWIFT_FLAGS, necessary to build swift target
|
||||
post_install do |installer|
|
||||
file_name = Dir.glob("*.xcodeproj")[0]
|
||||
app_project = Xcodeproj::Project.open(file_name)
|
||||
app_project.native_targets.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
if (config.build_settings['OTHER_SWIFT_FLAGS'])
|
||||
unless config.build_settings['OTHER_SWIFT_FLAGS'].include? '-DFB_SONARKIT_ENABLED'
|
||||
puts 'Adding -DFB_SONARKIT_ENABLED ...'
|
||||
swift_flags = config.build_settings['OTHER_SWIFT_FLAGS']
|
||||
if swift_flags.split.last != '-Xcc'
|
||||
config.build_settings['OTHER_SWIFT_FLAGS'] << ' -Xcc'
|
||||
end
|
||||
config.build_settings['OTHER_SWIFT_FLAGS'] << ' -DFB_SONARKIT_ENABLED'
|
||||
end
|
||||
else
|
||||
puts 'OTHER_SWIFT_FLAGS does not exist thus assigning it to `$(inherited) -Xcc -DFB_SONARKIT_ENABLED`'
|
||||
config.build_settings['OTHER_SWIFT_FLAGS'] = '$(inherited) -Xcc -DFB_SONARKIT_ENABLED'
|
||||
end
|
||||
app_project.save
|
||||
end
|
||||
end
|
||||
installer.pods_project.save
|
||||
end
|
||||
end
|
||||
@@ -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