Skip to content

Commit

Permalink
NativeBook integration
Browse files Browse the repository at this point in the history
  • Loading branch information
psharanda committed Jan 8, 2024
1 parent c13064d commit ddb50cc
Show file tree
Hide file tree
Showing 342 changed files with 2,913 additions and 0 deletions.
597 changes: 597 additions & 0 deletions FixFlexSamples.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"pins" : [
{
"identity" : "ios-snapshot-test-case",
"kind" : "remoteSourceControl",
"location" : "https://github.com/uber/ios-snapshot-test-case",
"state" : {
"revision" : "7b10770333a961be6e5a41c9ce04b8c6d3990126",
"version" : "8.0.0"
}
},
{
"identity" : "swiftuikitview",
"kind" : "remoteSourceControl",
"location" : "https://github.com/AvdLee/SwiftUIKitView",
"state" : {
"revision" : "56f2a1f8e35d5c258f633e8472cd59345ed5ae59",
"version" : "2.0.0"
}
}
],
"version" : 2
}
118 changes: 118 additions & 0 deletions FixFlexSamples.xcodeproj/xcshareddata/xcschemes/NativeBook.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1BDD34842B1BC3A300B19632"
BuildableName = "FixFlexSamples.app"
BlueprintName = "FixFlexSamples"
ReferencedContainer = "container:FixFlexSamples.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:FixFlexSamples.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1BDD349A2B1BC3A500B19632"
BuildableName = "FixFlexSamplesTests.xctest"
BlueprintName = "FixFlexSamplesTests"
ReferencedContainer = "container:FixFlexSamples.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1BDD34A42B1BC3A500B19632"
BuildableName = "FixFlexSamplesUITests.xctest"
BlueprintName = "FixFlexSamplesUITests"
ReferencedContainer = "container:FixFlexSamples.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1BDD34842B1BC3A300B19632"
BuildableName = "FixFlexSamples.app"
BlueprintName = "FixFlexSamples"
ReferencedContainer = "container:FixFlexSamples.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "IMAGE_DIFF_DIR"
value = "$(SOURCE_ROOT)/Ref/FailureDiffs"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "FB_REFERENCE_IMAGE_DIR"
value = "$(SOURCE_ROOT)/Ref/ReferenceImages"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1BDD34842B1BC3A300B19632"
BuildableName = "FixFlexSamples.app"
BlueprintName = "FixFlexSamples"
ReferencedContainer = "container:FixFlexSamples.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
38 changes: 38 additions & 0 deletions FixFlexSamples.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"configurations" : [
{
"id" : "C7479585-2C92-420D-A6D7-DADE5B4674D9",
"name" : "Test Scheme Action",
"options" : {

}
}
],
"defaultOptions" : {
"environmentVariableEntries" : [
{
"key" : "IMAGE_DIFF_DIR",
"value" : "$(SOURCE_ROOT)\/Ref\/FailureDiffs"
},
{
"key" : "FB_REFERENCE_IMAGE_DIR",
"value" : "$(SOURCE_ROOT)\/Ref\/ReferenceImages"
}
],
"targetForVariableExpansion" : {
"containerPath" : "container:FixFlexSamples.xcodeproj",
"identifier" : "1BDD34842B1BC3A300B19632",
"name" : "FixFlexSamples"
}
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:FixFlexSamples.xcodeproj",
"identifier" : "1BDD349A2B1BC3A500B19632",
"name" : "FixFlexSamplesTests"
}
}
],
"version" : 1
}
27 changes: 27 additions & 0 deletions FixFlexSamples/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Created by Pavel Sharanda on 02/12/2023.
//

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

// MARK: UISceneSession Lifecycle

func application(_: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options _: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_: UIApplication, didDiscardSceneSessions _: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
11 changes: 11 additions & 0 deletions FixFlexSamples/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
13 changes: 13 additions & 0 deletions FixFlexSamples/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions FixFlexSamples/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
25 changes: 25 additions & 0 deletions FixFlexSamples/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
50 changes: 50 additions & 0 deletions FixFlexSamples/Core/Base.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Created by Pavel Sharanda on 03/12/2023.
//

import UIKit

struct Story {
let name: String
let makeView: () -> UIView
}

protocol ComponentStories {
var componentName: String { get }
var stories: [Story] { get }
}

class DynamicComponentStories: NSObject, ComponentStories {
var componentName: String {
return NSStringFromClass(type(of: self))
.split(separator: ".").last!
.replacingOccurrences(of: "Stories", with: "")
}

private(set) lazy var stories: [Story] = {
var methodCount: UInt32 = 0

guard let methodList = class_copyMethodList(object_getClass(type(of: self)), &methodCount) else { return [] }

var uniqueSelectors = Set<String>()
var selectors = [Selector]()
for i in 0 ..< Int(methodCount) {
let selector = method_getName(methodList[i])
let name = NSStringFromSelector(selector)
if name.starts(with: "story_") {
if !uniqueSelectors.contains(name) {
uniqueSelectors.insert(name)
selectors.append(selector)
}
}
}
free(methodList)

let cls = type(of: self)
return selectors.map { selector in
Story(name: NSStringFromSelector(selector).replacingOccurrences(of: "story_", with: "")) {
cls.perform(selector).takeUnretainedValue() as! UIView
}
}
}()
}
11 changes: 11 additions & 0 deletions FixFlexSamples/Core/PreviewContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import SwiftUI
import SwiftUIKitView

func previewStories(_ stories: [Story]) -> ForEach<[Story], String, some View> {
return ForEach(stories, id: \.name) { story in
UIViewContainer(story.makeView(), layout: .intrinsic)
.fixedSize()
.previewDisplayName(story.name)
.previewLayout(.sizeThatFits)
}
}
37 changes: 37 additions & 0 deletions FixFlexSamples/Core/StoryViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Created by Pavel Sharanda on 03/12/2023.
//

import CoreImage
import UIKit

class StoryViewController: UIViewController {
let story: Story
init(story: Story) {
self.story = story
super.init(nibName: nil, bundle: nil)
title = story.name
}

@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .secondarySystemBackground

let storyView = story.makeView()

view.addSubview(storyView)

storyView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
storyView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
storyView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
}
}
Loading

0 comments on commit ddb50cc

Please sign in to comment.