Skip to content

Added swiftUI example app #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions TaboolaSDKExampleSwiftUiUmbrella/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Taboola iOS SDK SwiftUI Examples

Taboola SDK allows publishers to display Taboola's Widgets and Feed within their iOS apps.

## Getting Started
To get started with the Taboola iOS SDK, please follow this link [iOS SDK documentation](https://sdk.taboola.com/taboolasdk/docs/taboola-ios-sdk-install?ref=github).
SwiftUI provides a new way of composing layout by following declaritive approach. This tutorial encompasses basics UI components like ListView, ScrollView, VStackView etc. with Taboola placements.
Also, we use Taboola-SwiftUI-Umbrella framework to utilize several essential components which help combine Taboola placement and SwiftUI in an easy way with less effort.

## Change log
Taboola iOS SDK [change log](https://developers.taboola.com/taboolasdk/docs/ios-changelog).

## Contact Us
If you wish to integrate Taboola SDK into any commercial applications, please [contact us](https://www.taboola.com/contact?ref=taboola_sdk_github_examples).
For more information and support, please contact your dedicated account manager

## Legal
Using the example code in the repository is subject to Taboola [terms of use](https://www.taboola.com/terms-of-use) and [privacy policy](https://www.taboola.com/privacy-policy).

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>

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,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D80E149F283B8BD40014FD09"
BuildableName = "ios-sdk-swift-ui-examples-4x.app"
BlueprintName = "ios-sdk-swift-ui-examples-4x"
ReferencedContainer = "container:ios-sdk-swift-ui-examples-4x.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</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 = "D80E149F283B8BD40014FD09"
BuildableName = "ios-sdk-swift-ui-examples-4x.app"
BlueprintName = "ios-sdk-swift-ui-examples-4x"
ReferencedContainer = "container:ios-sdk-swift-ui-examples-4x.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D80E149F283B8BD40014FD09"
BuildableName = "ios-sdk-swift-ui-examples-4x.app"
BlueprintName = "ios-sdk-swift-ui-examples-4x"
ReferencedContainer = "container:ios-sdk-swift-ui-examples-4x.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// ClassicPageWrapper.swift
// TaboolaSwiftUI
//
// Copyright © 2022 Taboola. All rights reserved.
//

import TaboolaSDK
import TaboolaSDK_SwiftUI_Umbrella

class ClassicPageWrapper: NSObject, TBLClassicPageDelegate, СlassicPageWrappable {

var page: TBLClassicPage!
@Weak var delegates: [Coordinator]

let reusableViewsQueue = ReusableViewsQueue<String, TBLClassicUnit>()

init(pageType: String, pageUrl: String) {
super.init()

page = TBLClassicPage(pageType: pageType, pageUrl: pageUrl, delegate: self, scrollView: nil)
page.pageExtraProperties = ["disableScrollIntercept": NSNumber(value: true)]
}

// MARK: - TBLClassicPageDelegate

func classicUnit(_ classicUnit: UIView!,
didLoadOrResizePlacementName placementName: String!,
height: CGFloat,
placementType: PlacementType) {
let delegates = delegates.filter { placementName.contains($0.unit.placement) }
delegates.forEach { $0.didLoadWithHeight(height: height) }
}

func classicUnit(_ classicUnit: UIView!,
didClickPlacementName placementName: String!,
itemId: String!,
clickUrl: String!,
isOrganic organic: Bool) -> Bool {
return organic
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// ClassicLazyVGrid.swift
// TaboolaSwiftUI
//
// Copyright © 2022 Taboola. All rights reserved.
//

import SwiftUI
import TaboolaSDK_SwiftUI_Umbrella

struct ClassicLazyVGrid: View {

let colors: [Color] = [.red, .green, .yellow, .blue]
var columns: [GridItem] = Array(repeating: .init(.flexible(), alignment: .center), count: 1)
let title: String
let pageWrapper = ClassicPageWrapper(pageType: Constants.article,
pageUrl: Constants.pageUrl)

@State var topHeight: CGFloat = 0
@State var feedHeight: CGFloat = 0

var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 10) {
ForEach(0...2, id: \.self) { index in
switch index {
case 0:
ClassicUnitSwiftUI(pageWrapper: pageWrapper,
placement: Constants.widgetPlacement,
mode: Constants.mode,
height: $topHeight).frame(height:topHeight)
.background(colors[index % colors.count])
.cornerRadius(8)
case 1:
Text("Cell \(index)")
.frame(width: 110, height: 500)
.background(colors[index % colors.count])
.cornerRadius(8)
default:
ClassicUnitSwiftUI(pageWrapper: pageWrapper,
placement: Constants.feedPlacement,
mode: Constants.mode,
height: $feedHeight).frame(height:feedHeight)
.background(colors[index % colors.count])
.cornerRadius(8)
}
}
}
}
}
}

struct LazyVGridView_Previews: PreviewProvider {
static var previews: some View {
ClassicLazyVGrid(title: "LazyVGrid")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// ClassicLazyVStack.swift
// TaboolaSwiftUI
//
// Copyright © 2022 Taboola. All rights reserved.
//

import SwiftUI
import TaboolaSDK_SwiftUI_Umbrella

struct ClassicLazyVStack: View {

let title: String
let pageWrapper = ClassicPageWrapper(pageType: Constants.article,
pageUrl: Constants.pageUrl)

@State var topHeight: CGFloat = 0
@State var feedHeight: CGFloat = 0

var body: some View {
ScrollView {
LazyVStack {
LoremText()
ClassicUnitSwiftUI(pageWrapper: pageWrapper,
placement: Constants.widgetPlacement,
mode: Constants.mode,
height: $topHeight).frame(height: topHeight)
LoremText()
ClassicUnitSwiftUI(pageWrapper: pageWrapper,
placement: Constants.feedPlacement,
mode: Constants.mode,
height: $feedHeight).frame(height: feedHeight)
}
}
.navigationBarTitle(title, displayMode: .inline)
}
}

struct LazyVStackView_Previews: PreviewProvider {
static var previews: some View {
ClassicLazyVStack(title: "LazyVStack")
}
}
Loading