Skip to content

Commit

Permalink
Merge pull request #215 from player-ui/177-enhance-demo-app
Browse files Browse the repository at this point in the history
177/ add plugin examples and managed player to demo app
  • Loading branch information
nancywu1 authored Nov 23, 2023
2 parents 98d4e5a + 4251f7b commit 7b82ec7
Show file tree
Hide file tree
Showing 19 changed files with 1,044 additions and 18 deletions.
1 change: 0 additions & 1 deletion ios/packages/core/Sources/Types/Core/FlowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@ public class FlowController: CreatedFromJSValue {
value.invokeMethod("transition", withArguments: [action])
}
}

7 changes: 4 additions & 3 deletions ios/packages/demo/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ class SceneDelegate: UIResponder, UISceneDelegate {

window.loadView(
view: NavigationView {
AssetCollection(
SegmentControlView(
plugins: plugins,
sections: MockFlows.sections,
completion: self.completion(result:)
assetSections: MockFlows.assetSections,
pluginSections: MockFlows.pluginSections,
completion: completion(result:)
)
.navigationBarTitleDisplayMode(.inline)
},
Expand Down
71 changes: 71 additions & 0 deletions ios/packages/demo/Sources/FlowManagerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// FlowManagerView.swift
// Pods
//
// Created by Zhao Xia Wu on 2023-11-01.
//

import SwiftUI
import PlayerUI

/**
SwiftUI View to wrap the `ManagedPlayer` and handle the result
for use in UI testing
*/
public struct FlowManagerView: View {
let flowSequence: [String]
let navTitle: String
@State private var complete = false

public var body: some View {
VStack {
if complete {
VStack {
Text("Flow Completed").font(.title)
Button(action: {complete = false}, label: { Text("Start Over " )})
}
} else {
VStack {
ManagedPlayer(
plugins: [
ReferenceAssetsPlugin(),
MetricsPlugin { (render, _, flow) in
print("Render: \(render?.duration ?? 0 )ms | Request \(flow?.flow.requestTime ?? 0)ms")
}
],
flowManager: ConstantFlowManager(flowSequence),
onComplete: { _ in
complete = true
},
fallback: { (context) in
VStack {
Text(context.error.localizedDescription)

switch context.error as? PlayerError {
case .promiseRejected(error: let errorState) :
Text(errorState.error)
default:
EmptyView()
}

Button(action: context.retry, label: {
Text("Retry")
})
Button(action: context.reset, label: {
Text("Reset")
})
}.accessibility(identifier: "FallbackView")
},
loading: {
Text("Loading Flow")
}
)

Button(action: { complete = true }) {
Text("Terminate Flow")
}
}
}
}.navigationBarTitle(Text(navTitle))
}
}
229 changes: 228 additions & 1 deletion ios/packages/demo/Sources/MockFlows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,218 @@ static let textWithLink: String = """
}
}
"""
public static let sections: [FlowLoader.FlowSection] = [
static let beaconAction: String = """
{
"id": "generated-flow",
"views": [
{
"id": "action",
"type": "action",
"exp": [
"{{count}} = {{count}} + 1",
"beacon('action', 'some-data')"
],
"metaData": {
"beacon": "Click count: {{count}}"
},
"label": {
"asset": {
"id": "action-label-text",
"type": "text",
"value": "Clicked {{count}} times"
}
}
}
],
"data": {
"count": 0
},
"navigation": {
"BEGIN": "FLOW_1",
"FLOW_1": {
"startState": "VIEW_1",
"VIEW_1": {
"state_type": "VIEW",
"ref": "action",
"transitions": {
"*": "END_Done"
}
},
"END_Done": {
"state_type": "END",
"outcome": "done"
}
}
}
}
"""
static let externalAction: String = """
{
"id": "test-flow",
"data": {
"transitionValue": "Next"
},
"navigation": {
"BEGIN": "FLOW_1",
"FLOW_1": {
"startState": "EXT_1",
"EXT_1": {
"state_type": "EXTERNAL",
"ref": "test-1",
"transitions": {
"Next": "END_FWD",
"Prev": "END_BCK"
}
},
"END_FWD": {
"state_type": "END",
"outcome": "FWD"
},
"END_BCK": {
"state_type": "END",
"outcome": "BCK"
}
}
}
}
"""
static let pubSubBasic: String = """
{
"id": "generated-flow",
"views": [
{
"id": "action",
"type": "action",
"exp": "@[ publish('some-event', 'event published message') ]@",
"label": {
"asset": {
"id": "action-label",
"type": "text",
"value": "Clicked to publish event"
}
}
}
],
"data": {
"count": 0
},
"navigation": {
"BEGIN": "FLOW_1",
"FLOW_1": {
"startState": "VIEW_1",
"VIEW_1": {
"state_type": "VIEW",
"ref": "action",
"transitions": {
"*": "END_Done"
}
},
"END_Done": {
"state_type": "END",
"outcome": "done"
}
}
}
}
"""


static let inputAssetPendingTransaction: String = """
{
"id": "input-validation-flow",
"views": [
{
"id": "view-1",
"type": "collection",
"values": [
{
"asset": {
"id": "input-required",
"type": "input",
"binding": "foo.requiredInput",
"label": {
"asset": {
"id": "input-required-label",
"type": "text",
"value": "This input is required and must be greater than 0"
}
}
}
},
{
"asset": {
"id": "action-1",
"type": "action",
"value": "Next",
"label": {
"asset": {
"id": "action-1-label",
"type": "text",
"value": "Continue"
}
}
}
}
]
},
{
"id": "view-2",
"type": "info",
"title": {
"asset": {
"id": "view-2-title",
"type": "text",
"value": "You made it!"
}
}
}
],
"schema": {
"ROOT": {
"foo": {
"type": "FooType"
}
},
"FooType": {
"requiredInput": {
"type": "IntegerPosType",
"validation": [
{
"type": "required"
}
]
}
}
},
"data": {},
"navigation": {
"BEGIN": "FLOW_1",
"FLOW_1": {
"startState": "VIEW_1",
"VIEW_1": {
"state_type": "VIEW",
"ref": "view-1",
"transitions": {
"*": "VIEW_2"
}
},
"VIEW_2": {
"state_type": "VIEW",
"ref": "view-2",
"transitions": {
"*": "END_Done"
}
},
"END_Done": {
"state_type": "END",
"outcome": "done"
}
}
}
}
"""

public static let assetSections: [FlowLoader.FlowSection] = [
(title: "action", flows: [
(name: "counter", flow: MockFlows.actionCounter),
(name: "transition to end", flow: MockFlows.actionTransitionToEnd),
Expand Down Expand Up @@ -1220,4 +1431,20 @@ static let textWithLink: String = """
(name: "with link", flow: MockFlows.textWithLink)
])
]

public static let pluginSections: [FlowLoader.FlowSection] = [
(title: "beacon", flows: [
(name: "action", flow: MockFlows.beaconAction)
]),
(title: "external-action", flows: [
(name: "external-action", flow: MockFlows.externalAction)
]),
(title: "pubsub", flows: [
(name: "pub sub basic", flow: MockFlows.pubSubBasic)
])
,
(title: "pending-transaction", flows: [
(name: "input asset pending transaction", flow: MockFlows.inputAssetPendingTransaction)
])
]
}
Loading

0 comments on commit 7b82ec7

Please sign in to comment.