From 71f634bec4a7077b8d4348b980c5219a68e20dae Mon Sep 17 00:00:00 2001 From: burstein Date: Fri, 4 Jul 2025 00:14:49 +0300 Subject: [PATCH] DivKit SwiftUI Sample App commit_hash:89fe30647b25dbbfb4349af0173ca6023d3a2e29 --- .mapping.json | 43 +- client/ios/README.md | 7 +- client/ios/Sample/README.md | 21 - client/ios/Samples/README.md | 47 +++ .../DivKitSample.xcodeproj/project.pbxproj | 388 ++++++++++++++++++ .../contents.xcworkspacedata | 0 .../AccentColor.colorset/Contents.json | 0 .../AppIcon.appiconset/Contents.json | 85 ++++ .../Assets.xcassets/Contents.json | 0 .../DivKitSample/ContentView.swift | 33 ++ .../DivKitSample/DivKitSample.entitlements | 10 + .../DivKitSample/DivKitSampleApp.swift | 10 + .../DivKitSample/Sample.json | 352 ++++++++++++++++ .../DivKitSample/SampleDivActionHandler.swift | 30 ++ .../SampleDivCustomBlockFactory.swift | 0 .../DivKitSample.xcodeproj/project.pbxproj | 0 .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../xcschemes/DivKitSample.xcscheme | 0 .../DivKitSample/AppDelegate.swift | 0 .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 0 .../Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 0 .../DivKitSample/Base.lproj/Main.storyboard | 0 .../DivKitSample/DivHostViewController.swift | 0 .../UIKitIntegration}/DivKitSample/Info.plist | 0 .../DivKitSample/Sample.json | 0 .../DivKitSample/SampleDivActionHandler.swift | 0 .../SampleDivCustomBlockFactory.swift | 63 +++ 30 files changed, 1073 insertions(+), 40 deletions(-) delete mode 100644 client/ios/Sample/README.md create mode 100644 client/ios/Samples/README.md create mode 100644 client/ios/Samples/SwiftUIIntegration/DivKitSample.xcodeproj/project.pbxproj rename client/ios/{Sample => Samples/SwiftUIIntegration}/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata (100%) rename client/ios/{Sample => Samples/SwiftUIIntegration}/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json (100%) create mode 100644 client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json rename client/ios/{Sample => Samples/SwiftUIIntegration}/DivKitSample/Assets.xcassets/Contents.json (100%) create mode 100644 client/ios/Samples/SwiftUIIntegration/DivKitSample/ContentView.swift create mode 100644 client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSample.entitlements create mode 100644 client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSampleApp.swift create mode 100644 client/ios/Samples/SwiftUIIntegration/DivKitSample/Sample.json create mode 100644 client/ios/Samples/SwiftUIIntegration/DivKitSample/SampleDivActionHandler.swift rename client/ios/{Sample => Samples/SwiftUIIntegration}/DivKitSample/SampleDivCustomBlockFactory.swift (100%) rename client/ios/{Sample => Samples/UIKitIntegration}/DivKitSample.xcodeproj/project.pbxproj (100%) create mode 100644 client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename client/ios/{Sample => Samples/UIKitIntegration}/DivKitSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) rename client/ios/{Sample => Samples/UIKitIntegration}/DivKitSample.xcodeproj/xcshareddata/xcschemes/DivKitSample.xcscheme (100%) rename client/ios/{Sample => Samples/UIKitIntegration}/DivKitSample/AppDelegate.swift (100%) create mode 100644 client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json rename client/ios/{Sample => Samples/UIKitIntegration}/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) create mode 100644 client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/Contents.json rename client/ios/{Sample => Samples/UIKitIntegration}/DivKitSample/Base.lproj/LaunchScreen.storyboard (100%) rename client/ios/{Sample => Samples/UIKitIntegration}/DivKitSample/Base.lproj/Main.storyboard (100%) rename client/ios/{Sample => Samples/UIKitIntegration}/DivKitSample/DivHostViewController.swift (100%) rename client/ios/{Sample => Samples/UIKitIntegration}/DivKitSample/Info.plist (100%) rename client/ios/{Sample => Samples/UIKitIntegration}/DivKitSample/Sample.json (100%) rename client/ios/{Sample => Samples/UIKitIntegration}/DivKitSample/SampleDivActionHandler.swift (100%) create mode 100644 client/ios/Samples/UIKitIntegration/DivKitSample/SampleDivCustomBlockFactory.swift diff --git a/.mapping.json b/.mapping.json index 5239206cf..6c6e65007 100644 --- a/.mapping.json +++ b/.mapping.json @@ -14526,22 +14526,33 @@ "client/ios/LayoutKitSnapshotTests/YSFontProvider.swift":"divkit/public/client/ios/LayoutKitSnapshotTests/YSFontProvider.swift", "client/ios/Package.swift":"divkit/public/client/ios/Package.swift", "client/ios/README.md":"divkit/public/client/ios/README.md", - "client/ios/Sample/DivKitSample.xcodeproj/project.pbxproj":"divkit/public/client/ios/Sample/DivKitSample.xcodeproj/project.pbxproj", - "client/ios/Sample/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata":"divkit/public/client/ios/Sample/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata", - "client/ios/Sample/DivKitSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist":"divkit/public/client/ios/Sample/DivKitSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist", - "client/ios/Sample/DivKitSample.xcodeproj/xcshareddata/xcschemes/DivKitSample.xcscheme":"divkit/public/client/ios/Sample/DivKitSample.xcodeproj/xcshareddata/xcschemes/DivKitSample.xcscheme", - "client/ios/Sample/DivKitSample/AppDelegate.swift":"divkit/public/client/ios/Sample/DivKitSample/AppDelegate.swift", - "client/ios/Sample/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json":"divkit/public/client/ios/Sample/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json", - "client/ios/Sample/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json":"divkit/public/client/ios/Sample/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json", - "client/ios/Sample/DivKitSample/Assets.xcassets/Contents.json":"divkit/public/client/ios/Sample/DivKitSample/Assets.xcassets/Contents.json", - "client/ios/Sample/DivKitSample/Base.lproj/LaunchScreen.storyboard":"divkit/public/client/ios/Sample/DivKitSample/Base.lproj/LaunchScreen.storyboard", - "client/ios/Sample/DivKitSample/Base.lproj/Main.storyboard":"divkit/public/client/ios/Sample/DivKitSample/Base.lproj/Main.storyboard", - "client/ios/Sample/DivKitSample/DivHostViewController.swift":"divkit/public/client/ios/Sample/DivKitSample/DivHostViewController.swift", - "client/ios/Sample/DivKitSample/Info.plist":"divkit/public/client/ios/Sample/DivKitSample/Info.plist", - "client/ios/Sample/DivKitSample/Sample.json":"divkit/public/client/ios/Sample/DivKitSample/Sample.json", - "client/ios/Sample/DivKitSample/SampleDivActionHandler.swift":"divkit/public/client/ios/Sample/DivKitSample/SampleDivActionHandler.swift", - "client/ios/Sample/DivKitSample/SampleDivCustomBlockFactory.swift":"divkit/public/client/ios/Sample/DivKitSample/SampleDivCustomBlockFactory.swift", - "client/ios/Sample/README.md":"divkit/public/client/ios/Sample/README.md", + "client/ios/Samples/README.md":"divkit/public/client/ios/Samples/README.md", + "client/ios/Samples/SwiftUIIntegration/DivKitSample.xcodeproj/project.pbxproj":"divkit/public/client/ios/Samples/SwiftUIIntegration/DivKitSample.xcodeproj/project.pbxproj", + "client/ios/Samples/SwiftUIIntegration/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata":"divkit/public/client/ios/Samples/SwiftUIIntegration/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata", + "client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json":"divkit/public/client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json", + "client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json":"divkit/public/client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json", + "client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/Contents.json":"divkit/public/client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/Contents.json", + "client/ios/Samples/SwiftUIIntegration/DivKitSample/ContentView.swift":"divkit/public/client/ios/Samples/SwiftUIIntegration/DivKitSample/ContentView.swift", + "client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSample.entitlements":"divkit/public/client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSample.entitlements", + "client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSampleApp.swift":"divkit/public/client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSampleApp.swift", + "client/ios/Samples/SwiftUIIntegration/DivKitSample/Sample.json":"divkit/public/client/ios/Samples/SwiftUIIntegration/DivKitSample/Sample.json", + "client/ios/Samples/SwiftUIIntegration/DivKitSample/SampleDivActionHandler.swift":"divkit/public/client/ios/Samples/SwiftUIIntegration/DivKitSample/SampleDivActionHandler.swift", + "client/ios/Samples/SwiftUIIntegration/DivKitSample/SampleDivCustomBlockFactory.swift":"divkit/public/client/ios/Samples/SwiftUIIntegration/DivKitSample/SampleDivCustomBlockFactory.swift", + "client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.pbxproj":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.pbxproj", + "client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata", + "client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist", + "client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/xcshareddata/xcschemes/DivKitSample.xcscheme":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/xcshareddata/xcschemes/DivKitSample.xcscheme", + "client/ios/Samples/UIKitIntegration/DivKitSample/AppDelegate.swift":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample/AppDelegate.swift", + "client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json", + "client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json", + "client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/Contents.json":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/Contents.json", + "client/ios/Samples/UIKitIntegration/DivKitSample/Base.lproj/LaunchScreen.storyboard":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample/Base.lproj/LaunchScreen.storyboard", + "client/ios/Samples/UIKitIntegration/DivKitSample/Base.lproj/Main.storyboard":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample/Base.lproj/Main.storyboard", + "client/ios/Samples/UIKitIntegration/DivKitSample/DivHostViewController.swift":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample/DivHostViewController.swift", + "client/ios/Samples/UIKitIntegration/DivKitSample/Info.plist":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample/Info.plist", + "client/ios/Samples/UIKitIntegration/DivKitSample/Sample.json":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample/Sample.json", + "client/ios/Samples/UIKitIntegration/DivKitSample/SampleDivActionHandler.swift":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample/SampleDivActionHandler.swift", + "client/ios/Samples/UIKitIntegration/DivKitSample/SampleDivCustomBlockFactory.swift":"divkit/public/client/ios/Samples/UIKitIntegration/DivKitSample/SampleDivCustomBlockFactory.swift", "client/ios/Serialization/Deserializable.swift":"divkit/public/client/ios/Serialization/Deserializable.swift", "client/ios/Serialization/DeserializationError.swift":"divkit/public/client/ios/Serialization/DeserializationError.swift", "client/ios/Serialization/DeserializationResult.swift":"divkit/public/client/ios/Serialization/DeserializationResult.swift", diff --git a/client/ios/README.md b/client/ios/README.md index b82be2722..d77ac428e 100644 --- a/client/ios/README.md +++ b/client/ios/README.md @@ -39,13 +39,14 @@ end Use `DivKitPlayground` scheme to build and run playground application. -Use `UnitTests` sheme to run all unit tests. +Use `UnitTests` scheme to run all unit tests. Use `SnapshotTests` scheme to run snapshot tests. -## Sample Project +## Sample Projects -`Sample/DivKitSample.xcodeproj` – sample project with simple DivKit integration using Swift Package Manager. +`Samples/UIKitIntegration/DivKitSample.xcodeproj` – sample project with simple DivKit integration using Swift Package Manager and UIKit. +`Samples/SwiftUIIntegration/DivKitSample.xcodeproj` – sample project with simple DivKit integration using Swift Package Manager and SwiftUI. --- diff --git a/client/ios/Sample/README.md b/client/ios/Sample/README.md deleted file mode 100644 index a277aaa37..000000000 --- a/client/ios/Sample/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# DivKit iOS. Quick start. -## Build an MVP. -Code-wise, connecting ```DivKit``` consists of three parts: initializing ```DivKitComponents```, parsing the ```JSON``` file with the layout, and adding DivView to your view hierarchy. -#### Initialize the DivKitComponents. -```DivKitComponents``` is basically just a container for client dependencies. We'll talk about them below. -#### Initialization the DivView. -To create a DivView, you need to provide a previously created DivKitComponents instance to the constructor. Subsequently, you should populate the DivView with the data to be displayed at the appropriate time. - -Initialization Example: -```Swift -let divView = DivView(divKitComponents: divKitComponents) -divView.setSource( - DivBlockProvider.Source( - kind: .json(json), - cardId: cardId - ), - debugParams: debugParams, - shouldResetPreviousCardData: true -) -``` - diff --git a/client/ios/Samples/README.md b/client/ios/Samples/README.md new file mode 100644 index 000000000..15d487f92 --- /dev/null +++ b/client/ios/Samples/README.md @@ -0,0 +1,47 @@ +# DivKit in iOS. Quick start. + +## Build an MVP. +Code-wise, connecting `DivKit` consists of three parts: initializing `DivKitComponents`, parsing the `JSON` file with the layout, and creating `DivHostingView` or `DivView` and adding it to your `SwiftUI` or `UIKit` hierarchy respectively. + +#### Creating DivKitComponents. +You should create `DivKitComponents` object and provide the necessary dependencies and handlers. + +#### Creating DivViewSource. +You should create DivViewSource where you need to provide `DivKit` data. This can be done in the following ways: +- raw `JSON` in `Dictionary` format +- `JSON` in `Swift.Data` format +- `DivData` object + +#### Creating DivKit View. +To create `DivView` (UIKit) or `DivHostingView` (SwiftUI), you need to provide a previously created `DivKitComponents` instance to the constructor. Subsequently, you should populate the `DivView` with the data to be displayed at the appropriate time in `UIKit` via `setSource` or provide `DivViewSource` to `DivHostingView` constructor in `SwiftUI`. + +## Initialization Example: + +#### UIKit +```Swift + let divView = DivView(divKitComponents: divKitComponents) + divView.setSource( + DivBlockProvider.Source( + kind: .json(json), + cardId: cardId + ), + debugParams: debugParams, + shouldResetPreviousCardData: true + ) +``` + +#### SwiftUI +```Swift + DivHostingView( + divkitComponents: DivKitComponents( + divCustomBlockFactory: SampleDivCustomBlockFactory(), + urlHandler: SampleDivActionHandler( + isPresented: $isPresented, + text: $text + ) + ), + source: DivViewSource(kind: .data(sampleData), cardId: "Sample"), + debugParams: DebugParams(isDebugInfoEnabled: true) + ) +``` + diff --git a/client/ios/Samples/SwiftUIIntegration/DivKitSample.xcodeproj/project.pbxproj b/client/ios/Samples/SwiftUIIntegration/DivKitSample.xcodeproj/project.pbxproj new file mode 100644 index 000000000..d440e5354 --- /dev/null +++ b/client/ios/Samples/SwiftUIIntegration/DivKitSample.xcodeproj/project.pbxproj @@ -0,0 +1,388 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 77; + objects = { + +/* Begin PBXBuildFile section */ + 9DC808452E0DFC47001FCE84 /* DivKit in Frameworks */ = {isa = PBXBuildFile; productRef = 9DC808442E0DFC47001FCE84 /* DivKit */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 9DC808232E0DAFB1001FCE84 /* DivKitSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DivKitSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 9DC808352E0DB17E001FCE84 /* DivKitSample.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = DivKitSample.xcodeproj; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFileSystemSynchronizedRootGroup section */ + 9DC808252E0DAFB1001FCE84 /* DivKitSample */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = DivKitSample; + sourceTree = ""; + }; +/* End PBXFileSystemSynchronizedRootGroup section */ + +/* Begin PBXFrameworksBuildPhase section */ + 9DC808202E0DAFB1001FCE84 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 9DC808452E0DFC47001FCE84 /* DivKit in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 9DC8081A2E0DAFB1001FCE84 = { + isa = PBXGroup; + children = ( + 9DC808252E0DAFB1001FCE84 /* DivKitSample */, + 9DC808432E0DFC47001FCE84 /* Frameworks */, + 9DC808242E0DAFB1001FCE84 /* Products */, + ); + sourceTree = ""; + }; + 9DC808242E0DAFB1001FCE84 /* Products */ = { + isa = PBXGroup; + children = ( + 9DC808232E0DAFB1001FCE84 /* DivKitSample.app */, + ); + name = Products; + sourceTree = ""; + }; + 9DC808372E0DB17E001FCE84 /* Products */ = { + isa = PBXGroup; + name = Products; + sourceTree = ""; + }; + 9DC808432E0DFC47001FCE84 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 9DC808222E0DAFB1001FCE84 /* DivKitSample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 9DC8082F2E0DAFB1001FCE84 /* Build configuration list for PBXNativeTarget "DivKitSample" */; + buildPhases = ( + 9DC8081F2E0DAFB1001FCE84 /* Sources */, + 9DC808202E0DAFB1001FCE84 /* Frameworks */, + 9DC808212E0DAFB1001FCE84 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + fileSystemSynchronizedGroups = ( + 9DC808252E0DAFB1001FCE84 /* DivKitSample */, + ); + name = DivKitSample; + packageProductDependencies = ( + 9DC808442E0DFC47001FCE84 /* DivKit */, + ); + productName = DivKitSample; + productReference = 9DC808232E0DAFB1001FCE84 /* DivKitSample.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 9DC8081B2E0DAFB1001FCE84 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1630; + LastUpgradeCheck = 1630; + TargetAttributes = { + 9DC808222E0DAFB1001FCE84 = { + CreatedOnToolsVersion = 16.3; + }; + }; + }; + buildConfigurationList = 9DC8081E2E0DAFB1001FCE84 /* Build configuration list for PBXProject "DivKitSample" */; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 9DC8081A2E0DAFB1001FCE84; + minimizedProjectReferenceProxies = 1; + packageReferences = ( + 9DC8083F2E0DB1C2001FCE84 /* XCRemoteSwiftPackageReference "divkit-ios" */, + ); + preferredProjectObjectVersion = 77; + productRefGroup = 9DC808242E0DAFB1001FCE84 /* Products */; + projectDirPath = ""; + projectReferences = ( + { + ProductGroup = 9DC808372E0DB17E001FCE84 /* Products */; + ProjectRef = 9DC808352E0DB17E001FCE84 /* DivKitSample.xcodeproj */; + }, + ); + projectRoot = ""; + targets = ( + 9DC808222E0DAFB1001FCE84 /* DivKitSample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 9DC808212E0DAFB1001FCE84 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 9DC8081F2E0DAFB1001FCE84 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 9DC8082D2E0DAFB1001FCE84 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 9DC8082E2E0DAFB1001FCE84 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SWIFT_COMPILATION_MODE = wholemodule; + }; + name = Release; + }; + 9DC808302E0DAFB1001FCE84 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = DivKitSample/DivKitSample.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 18.4; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 15.3; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = tech.divkit.swiftui.DivKitSample; + PRODUCT_NAME = "$(TARGET_NAME)"; + REGISTER_APP_GROUPS = YES; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2,7"; + XROS_DEPLOYMENT_TARGET = 2.4; + }; + name = Debug; + }; + 9DC808312E0DAFB1001FCE84 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = DivKitSample/DivKitSample.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; + "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; + "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 18.4; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 15.3; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = tech.divkit.swiftui.DivKitSample; + PRODUCT_NAME = "$(TARGET_NAME)"; + REGISTER_APP_GROUPS = YES; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2,7"; + XROS_DEPLOYMENT_TARGET = 2.4; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 9DC8081E2E0DAFB1001FCE84 /* Build configuration list for PBXProject "DivKitSample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 9DC8082D2E0DAFB1001FCE84 /* Debug */, + 9DC8082E2E0DAFB1001FCE84 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 9DC8082F2E0DAFB1001FCE84 /* Build configuration list for PBXNativeTarget "DivKitSample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 9DC808302E0DAFB1001FCE84 /* Debug */, + 9DC808312E0DAFB1001FCE84 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 9DC8083F2E0DB1C2001FCE84 /* XCRemoteSwiftPackageReference "divkit-ios" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/divkit/divkit-ios.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 32.5.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 9DC808442E0DFC47001FCE84 /* DivKit */ = { + isa = XCSwiftPackageProductDependency; + package = 9DC8083F2E0DB1C2001FCE84 /* XCRemoteSwiftPackageReference "divkit-ios" */; + productName = DivKit; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 9DC8081B2E0DAFB1001FCE84 /* Project object */; +} diff --git a/client/ios/Sample/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/client/ios/Samples/SwiftUIIntegration/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from client/ios/Sample/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to client/ios/Samples/SwiftUIIntegration/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/client/ios/Sample/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json b/client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json similarity index 100% rename from client/ios/Sample/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json rename to client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json diff --git a/client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json b/client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..ffdfe150b --- /dev/null +++ b/client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,85 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "tinted" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/client/ios/Sample/DivKitSample/Assets.xcassets/Contents.json b/client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/Contents.json similarity index 100% rename from client/ios/Sample/DivKitSample/Assets.xcassets/Contents.json rename to client/ios/Samples/SwiftUIIntegration/DivKitSample/Assets.xcassets/Contents.json diff --git a/client/ios/Samples/SwiftUIIntegration/DivKitSample/ContentView.swift b/client/ios/Samples/SwiftUIIntegration/DivKitSample/ContentView.swift new file mode 100644 index 000000000..6c75430de --- /dev/null +++ b/client/ios/Samples/SwiftUIIntegration/DivKitSample/ContentView.swift @@ -0,0 +1,33 @@ +import SwiftUI +import DivKit + +struct ContentView: View { + @State private var isPresented: Bool = false + @State private var text: String = "" + + var body: some View { + DivHostingView( + divkitComponents: DivKitComponents( + divCustomBlockFactory: SampleDivCustomBlockFactory(), + urlHandler: SampleDivActionHandler( + isPresented: $isPresented, + text: $text + ) + ), + source: DivViewSource(kind: .data(sampleData), cardId: "Sample"), + debugParams: DebugParams(isDebugInfoEnabled: true) + ) + .alert("\(text)", isPresented: $isPresented) {} + } +} + +private let sampleData: Data = try! Data( + contentsOf: Bundle.main.url( + forResource: "Sample", + withExtension: "json" + )! +) + +#Preview { + ContentView() +} diff --git a/client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSample.entitlements b/client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSample.entitlements new file mode 100644 index 000000000..f2ef3ae02 --- /dev/null +++ b/client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSample.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSampleApp.swift b/client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSampleApp.swift new file mode 100644 index 000000000..24113808b --- /dev/null +++ b/client/ios/Samples/SwiftUIIntegration/DivKitSample/DivKitSampleApp.swift @@ -0,0 +1,10 @@ +import SwiftUI + +@main +struct DivKitSampleApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/client/ios/Samples/SwiftUIIntegration/DivKitSample/Sample.json b/client/ios/Samples/SwiftUIIntegration/DivKitSample/Sample.json new file mode 100644 index 000000000..da3614a04 --- /dev/null +++ b/client/ios/Samples/SwiftUIIntegration/DivKitSample/Sample.json @@ -0,0 +1,352 @@ +{ + "templates": { + "divgram_card": { + "type": "container", + "margins": { + "left": 12, + "right": 12, + "top": 12, + "bottom": 12 + }, + "background": [ + { + "type": "solid", + "color": "@{color.background}" + } + ], + "border": { + "corner_radius": 14, + "stroke": { + "color": "#666" + }, + "shadow": { + "offset": { + "x": { + "value": 1 + }, + "y": { + "value": 4 + } + }, + "color": "#000" + }, + "has_shadow": true + }, + "items": [ + { + "type": "image", + "$image_url": "post_image", + "aspect": { + "ratio": 1 + }, + "content_alignment_vertical": "top" + }, + { + "type": "container", + "orientation": "horizontal", + "margins": { + "left": 12, + "right": 12, + "top": 12, + "bottom": 12 + }, + "content_alignment_vertical": "center", + "items": [ + { + "type": "text", + "$text": "author", + "font_size": 18, + "ranges": [ + { + "start": 0, + "$end": "author_prefix_end", + "font_size": 14 + } + ] + } + ] + } + ] + } + }, + "card": { + "timers": [ + { + "id": "like_timer", + "tick_interval": 2000, + "tick_actions": [ + { + "log_id": "card0.add_timer_like", + "url": "@{card0.likes > 7 ? '' : 'div-action://set_variable?name=card0.likes&value=@{card0.likes + 1}'}" + } + ] + } + ], + "variables": [ + { + "name": "color.background", + "type": "color", + "value": "#5e6e7d" + }, + { + "name": "card0.likes", + "type": "integer", + "value": 5 + }, + { + "name": "card1.likes", + "type": "integer", + "value": 73 + }, + { + "name": "card2.likes", + "type": "integer", + "value": 1001001 + }, + { + "name": "cup.likes", + "type": "integer", + "value": 2 + }, + { + "name": "toast_text", + "type": "string", + "value": "" + } + ], + "log_id": "divgram", + "states": [ + { + "state_id": 0, + "div": { + "type": "gallery", + "orientation": "vertical", + "height": { + "type": "match_parent" + }, + "width": { + "type": "match_parent" + }, + "items": [ + { + "type": "container", + "orientation": "horizontal", + "content_alignment_vertical": "center", + "margins": { + "top": 12, + "left": 12, + "right": 12 + }, + "items": [ + { + "type": "input", + "hint_text": "Toast your mind", + "hint_color": "#666", + "width": { + "type": "match_parent" + }, + "height": { + "type": "match_parent" + }, + "text_variable": "toast_text", + "font_size": 20, + "text_color": "#FFF", + "paddings": { + "top": 10, + "left": 10, + "right": 10, + "bottom": 10 + }, + "margins": { + "top": 10, + "left": 10, + "right": 10, + "bottom": 10 + }, + "border": { + "stroke": { + "color": "@{color.background}" + }, + "corner_radius": 12 + } + }, + { + "type": "container", + "border": { + "corner_radius": 12 + }, + "background": [ + { + "type": "solid", + "color": "#4267B2" + } + ], + "width": { + "type": "wrap_content" + }, + "height": { + "type": "wrap_content" + }, + "content_alignment_vertical": "center", + "items": [ + { + "type": "text", + "text": "Toast!", + "paddings": { + "top": 10, + "left": 10, + "right": 10, + "bottom": 10 + }, + "width": { + "type": "wrap_content" + }, + "height": { + "type": "wrap_content" + }, + "font_size": 20, + "text_color": "#FFF", + "actions": [ + { + "log_id": "show_toast", + "url": "sample-action://toast?Toasted: @{toast_text}" + } + ] + } + ] + } + ] + }, + { + "type": "divgram_card", + "likes_counter": "@{card0.likes}", + "post_image": "https://yastatic.net/s3/home/divkit/wombat.jpg", + "author": "by @yandex_art", + "author_prefix_end": 3, + "state_likes_id": "card0.likes", + "visibility_actions": [ + { + "log_id": "card_visible", + "url": "div-action://timer?id=like_timer&action=start" + } + ], + "add_like_log_id": "card0.add_like", + "add_like_url": "div-action://set_variable?name=card0.likes&value=@{card0.likes + 1}", + "set_liked_log_id": "card0.set_liked", + "set_liked_url": "div-action://set_state?state_id=0/card0.likes/liked", + "remove_like_log_id": "card0.remove_like", + "remove_like_url": "div-action://set_variable?name=card0.likes&value=@{card0.likes - 1}", + "set_disliked_log_id": "card0.set_disliked", + "set_disliked_url": "div-action://set_state?state_id=0/card0.likes/disliked" + }, + { + "type": "divgram_card", + "likes_counter": "@{card1.likes}", + "post_image": "https://yastatic.net/s3/home/divkit/ducks.jpg", + "author": "from @shedevrum", + "author_prefix_end": 5, + "state_likes_id": "card1.likes", + "add_like_log_id": "card1.add_like", + "add_like_url": "div-action://set_variable?name=card1.likes&value=@{card1.likes + 1}", + "set_liked_log_id": "card1.set_liked", + "set_liked_url": "div-action://set_state?state_id=0/card1.likes/liked", + "remove_like_log_id": "card1.remove_like", + "remove_like_url": "div-action://set_variable?name=card1.likes&value=@{card1.likes - 1}", + "set_disliked_log_id": "card1.set_disliked", + "set_disliked_url": "div-action://set_state?state_id=0/card1.likes/disliked" + }, + { + "type": "divgram_card", + "likes_counter": "@{card2.likes}", + "post_image": "https://yastatic.net/s3/home/divkit/pupduck.jpg", + "author": "created by\n@me_and_you", + "author_prefix_end": 11, + "state_likes_id": "card2.likes", + "add_like_log_id": "card2.add_like", + "add_like_url": "div-action://set_variable?name=card2.likes&value=@{card2.likes + 1}", + "set_liked_log_id": "card2.set_liked", + "set_liked_url": "div-action://set_state?state_id=0/card2.likes/liked", + "remove_like_log_id": "card2.remove_like", + "remove_like_url": "div-action://set_variable?name=card2.likes&value=@{card2.likes - 1}", + "set_disliked_log_id": "card2.set_disliked", + "set_disliked_url": "div-action://set_state?state_id=0/card2.likes/disliked" + }, + { + "type": "container", + "margins": { + "left": 12, + "right": 12, + "top": 12, + "bottom": 12 + }, + "height": { + "type": "wrap_content" + }, + "background": [ + { + "type": "solid", + "color": "@{color.background}" + } + ], + "border": { + "corner_radius": 14, + "stroke": { + "color": "#666" + }, + "shadow": { + "offset": { + "x": { + "value": 1 + }, + "y": { + "value": 4 + } + }, + "color": "#000" + }, + "has_shadow": true + }, + "items": [ + { + "type": "custom", + "custom_type": "sample_custom", + "alignment_horizontal": "center", + "alignment_vertical": "center", + "custom_props": { + "text": "Sample custom", + "background_color": "#2C3E50" + } + }, + { + "type": "container", + "orientation": "horizontal", + "margins": { + "left": 12, + "right": 12, + "top": 12, + "bottom": 12 + }, + "content_alignment_vertical": "center", + "items": [ + { + "type": "text", + "text": "by @rive_app", + "font_size": 18, + "ranges": [ + { + "start": 0, + "end": 2, + "font_size": 14 + } + ] + } + ] + } + ] + } + ] + } + } + ] + } +} diff --git a/client/ios/Samples/SwiftUIIntegration/DivKitSample/SampleDivActionHandler.swift b/client/ios/Samples/SwiftUIIntegration/DivKitSample/SampleDivActionHandler.swift new file mode 100644 index 000000000..44697be06 --- /dev/null +++ b/client/ios/Samples/SwiftUIIntegration/DivKitSample/SampleDivActionHandler.swift @@ -0,0 +1,30 @@ +import DivKit +import SwiftUI + +final class SampleDivActionHandler: DivUrlHandler { + private let isPresented: Binding + private let text: Binding + + init(isPresented: Binding, text: Binding) { + self.isPresented = isPresented + self.text = text + } + + func handle(_ url: URL, info _: DivActionInfo, sender _: AnyObject?) { + guard let components = url.components, components.scheme == scheme else { + return + } + + switch components.host { + case "toast": + if let text = components.queryItems?.first?.name { + self.text.wrappedValue = text + self.isPresented.wrappedValue = true + } + default: + return + } + } +} + +private let scheme = "sample-action" diff --git a/client/ios/Sample/DivKitSample/SampleDivCustomBlockFactory.swift b/client/ios/Samples/SwiftUIIntegration/DivKitSample/SampleDivCustomBlockFactory.swift similarity index 100% rename from client/ios/Sample/DivKitSample/SampleDivCustomBlockFactory.swift rename to client/ios/Samples/SwiftUIIntegration/DivKitSample/SampleDivCustomBlockFactory.swift diff --git a/client/ios/Sample/DivKitSample.xcodeproj/project.pbxproj b/client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.pbxproj similarity index 100% rename from client/ios/Sample/DivKitSample.xcodeproj/project.pbxproj rename to client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.pbxproj diff --git a/client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..919434a62 --- /dev/null +++ b/client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/client/ios/Sample/DivKitSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from client/ios/Sample/DivKitSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/client/ios/Sample/DivKitSample.xcodeproj/xcshareddata/xcschemes/DivKitSample.xcscheme b/client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/xcshareddata/xcschemes/DivKitSample.xcscheme similarity index 100% rename from client/ios/Sample/DivKitSample.xcodeproj/xcshareddata/xcschemes/DivKitSample.xcscheme rename to client/ios/Samples/UIKitIntegration/DivKitSample.xcodeproj/xcshareddata/xcschemes/DivKitSample.xcscheme diff --git a/client/ios/Sample/DivKitSample/AppDelegate.swift b/client/ios/Samples/UIKitIntegration/DivKitSample/AppDelegate.swift similarity index 100% rename from client/ios/Sample/DivKitSample/AppDelegate.swift rename to client/ios/Samples/UIKitIntegration/DivKitSample/AppDelegate.swift diff --git a/client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json b/client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 000000000..eb8789700 --- /dev/null +++ b/client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/client/ios/Sample/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json b/client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from client/ios/Sample/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json rename to client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/Contents.json b/client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/client/ios/Samples/UIKitIntegration/DivKitSample/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/client/ios/Sample/DivKitSample/Base.lproj/LaunchScreen.storyboard b/client/ios/Samples/UIKitIntegration/DivKitSample/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from client/ios/Sample/DivKitSample/Base.lproj/LaunchScreen.storyboard rename to client/ios/Samples/UIKitIntegration/DivKitSample/Base.lproj/LaunchScreen.storyboard diff --git a/client/ios/Sample/DivKitSample/Base.lproj/Main.storyboard b/client/ios/Samples/UIKitIntegration/DivKitSample/Base.lproj/Main.storyboard similarity index 100% rename from client/ios/Sample/DivKitSample/Base.lproj/Main.storyboard rename to client/ios/Samples/UIKitIntegration/DivKitSample/Base.lproj/Main.storyboard diff --git a/client/ios/Sample/DivKitSample/DivHostViewController.swift b/client/ios/Samples/UIKitIntegration/DivKitSample/DivHostViewController.swift similarity index 100% rename from client/ios/Sample/DivKitSample/DivHostViewController.swift rename to client/ios/Samples/UIKitIntegration/DivKitSample/DivHostViewController.swift diff --git a/client/ios/Sample/DivKitSample/Info.plist b/client/ios/Samples/UIKitIntegration/DivKitSample/Info.plist similarity index 100% rename from client/ios/Sample/DivKitSample/Info.plist rename to client/ios/Samples/UIKitIntegration/DivKitSample/Info.plist diff --git a/client/ios/Sample/DivKitSample/Sample.json b/client/ios/Samples/UIKitIntegration/DivKitSample/Sample.json similarity index 100% rename from client/ios/Sample/DivKitSample/Sample.json rename to client/ios/Samples/UIKitIntegration/DivKitSample/Sample.json diff --git a/client/ios/Sample/DivKitSample/SampleDivActionHandler.swift b/client/ios/Samples/UIKitIntegration/DivKitSample/SampleDivActionHandler.swift similarity index 100% rename from client/ios/Sample/DivKitSample/SampleDivActionHandler.swift rename to client/ios/Samples/UIKitIntegration/DivKitSample/SampleDivActionHandler.swift diff --git a/client/ios/Samples/UIKitIntegration/DivKitSample/SampleDivCustomBlockFactory.swift b/client/ios/Samples/UIKitIntegration/DivKitSample/SampleDivCustomBlockFactory.swift new file mode 100644 index 000000000..4e13c9b95 --- /dev/null +++ b/client/ios/Samples/UIKitIntegration/DivKitSample/SampleDivCustomBlockFactory.swift @@ -0,0 +1,63 @@ +import DivKit +import Foundation +import LayoutKit +import UIKit +import VGSL + +struct SampleDivCustomBlockFactory: DivCustomBlockFactory { + public func makeBlock( + data: DivCustomData, + context _: DivBlockModelingContext + ) -> Block { + switch data.name { + case "sample_custom": + let text = data.data["text"] as? String ?? "" + return GenericViewBlock( + content: .view(SampleView(text: text)), + width: .resizable, + height: .fixed(200) + ) + default: + return EmptyBlock() + } + } +} + +private final class SampleView: UIView { + private let gradientLayer: CALayer = { + let gradientLayer = CAGradientLayer() + gradientLayer.colors = [UIColor.red.cgColor, UIColor.blue.cgColor] + gradientLayer.startPoint = CGPoint(x: 0, y: 0) + gradientLayer.endPoint = CGPoint(x: 1, y: 1) + return gradientLayer + }() + + private let label: UILabel = { + let label = UILabel() + label.textColor = .white + return label + }() + + init(text: String) { + super.init(frame: .zero) + setupView(text: text) + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + setupView() + } + + private func setupView(text: String = "") { + label.text = text + label.sizeToFit() + self.layer.insertSublayer(gradientLayer, at: 0) + self.addSubview(label) + } + + override func layoutSubviews() { + super.layoutSubviews() + label.center = bounds.center + gradientLayer.frame = bounds + } +}