From d9e328836d6fb634e92124805f4f2897d9887a8b Mon Sep 17 00:00:00 2001 From: edmishchenko <87074420+edmishchenko@users.noreply.github.com> Date: Mon, 29 Jan 2024 11:30:32 +0100 Subject: [PATCH] Update --- docs/css/getStarted.css | 22 +- docs/css/style.css | 21 +- docs/getStarted.html | 617 ++++++++++++++++++++++------------------ docs/img/icon_logo.png | Bin 0 -> 778 bytes docs/index.html | 22 +- 5 files changed, 373 insertions(+), 309 deletions(-) create mode 100644 docs/img/icon_logo.png diff --git a/docs/css/getStarted.css b/docs/css/getStarted.css index 4ff8419..ce7c03f 100644 --- a/docs/css/getStarted.css +++ b/docs/css/getStarted.css @@ -365,7 +365,10 @@ main .second-column .container .article-block p { margin-bottom: auto; } -main .second-column .container .article-block button { +main .second-column .container .article-block a { + display: flex; + align-items: center; + justify-content: center; height: 50px; border-radius: 4px; background: transparent; @@ -378,9 +381,11 @@ main .second-column .container .article-block button { font-family: 'Inter', sans-serif; margin-top: auto; margin-bottom: 18px; + text-decoration: none; + text-align: center; } -main .second-column .container .article-block button:hover { +main .second-column .container .article-block a:hover { background: rgba(241, 8, 55, 1); color: rgba(255, 255, 255, 1); } @@ -415,6 +420,7 @@ footer .social-media-container svg { @media (max-width: 992px) { header { + top: 0; position: fixed; background: #FFFFFF; width: 90%; @@ -426,7 +432,11 @@ footer .social-media-container svg { } main { - margin-top: 80px; + margin-top: 140px; + box-sizing: border-box; + position: fixed; + overflow-y: auto; + height: calc(100vh - 100px); } main .first-column { @@ -481,6 +491,12 @@ footer .social-media-container svg { animation: slideIn 0.5s ease-out; } + .footer { + padding-bottom: 100px; + width: 100%; + margin-top: 0; + } + @keyframes slideIn { from { transform: translateY(-100%); diff --git a/docs/css/style.css b/docs/css/style.css index f073884..7886cb0 100644 --- a/docs/css/style.css +++ b/docs/css/style.css @@ -5,7 +5,6 @@ html , body { } body { - width: 100%; margin: 0 auto; padding: 0; overflow: hidden; @@ -13,9 +12,9 @@ body { background-image: url("../img/background-desktop.png"); background-repeat: no-repeat; background-position: center; - background-attachment: fixed; background-size: cover; background-color: #0C0C2C; + background-attachment: fixed; display: flex; flex-direction: column; } @@ -56,7 +55,6 @@ main { position: absolute; left: 55%; top: 28vh; - /*bottom: -5%;*/ padding-left: 5%; } @@ -81,6 +79,7 @@ main { line-height: 0.99vw; cursor: pointer; font-family: 'Mona Sans', sans-serif; + text-decoration: none; } .content .download:hover { @@ -91,10 +90,6 @@ main { background: rgba(210, 4, 45, 1); } -.content .download-link { - text-decoration: none; -} - .content .get-started { background: transparent; border-radius: 0.5em; @@ -108,6 +103,7 @@ main { margin-left: 1.04vw; cursor: pointer; font-family: 'Mona Sans', sans-serif; + text-decoration: none; } .content .get-started:hover { @@ -127,7 +123,7 @@ main { color: rgba(255, 255, 255, 0.6); position: absolute; padding-top: 0.4vw; - margin-top: 0.4vw; + margin-top: 1.2vw; } .content .swift-for-android-text { @@ -193,9 +189,10 @@ footer .social-media-container svg { overflow-y: scroll; overflow-x: hidden; margin: 0 auto; - background-size: cover; - background-position: 69%; - background-repeat: no-repeat; + background-position: 69% top; + background-attachment: scroll; + background-size: 1190px auto; + background-color: rgb(18, 8, 66); } header .logo { @@ -256,7 +253,7 @@ footer .social-media-container svg { padding-bottom: 16px; } - .content .download { + .content .third-column .download { width: 100%; height: 59px; margin-top: 16px; diff --git a/docs/getStarted.html b/docs/getStarted.html index f5547a1..abb0559 100644 --- a/docs/getStarted.html +++ b/docs/getStarted.html @@ -5,7 +5,7 @@
- •Prerequisites
- •Install
- •Hello World
- •Go Further
+ •Prerequisites
+ •Install
+ •Hello World
+ •Go Further
Before you begin Swift development for Android, make sure you have the following tools installed: @@ -48,7 +48,7 @@
@@ -92,261 +92,261 @@
Currently Swift for Android is available for macOS only. It will be available for Linux very soon.-
Refer here to quickly create and run the app on Android Studio using Swift.
Refer here to quickly create and run the app on Android Studio using Swift.-
- cd SwiftAndroidExample/app/src/main/swift +++
- swift package init --name SwiftAndroidExample -- To create a new Swift Package Manager (SPM) project within the app/src/main/swift subdirectory, run the following commands in the terminal:
+
+cd SwiftAndroidExample/app/src/main/swift -- It will set up a new SPM project named SwiftAndroidExample inside the swift subdirectory. This project structure allows you to efficiently manage Swift dependencies and build your Swift code as a separate module within your Android Studio project. +swift package init --name SwiftAndroidExample+
+It will set up a new SPM project named SwiftAndroidExample inside the swift subdirectory. This project structure allows you to efficiently manage Swift dependencies and build your Swift code as a separate module within your Android Studio project. +-
- android { - sourceSets { - main { - jniLibs.srcDirs = ["lib"] - } ++
+ +- In your Android project, access the app/build.gradle file.
+- Enhance the android section by adding:
++- - ++android { + sourceSets { + main { + jniLibs.srcDirs = ["lib"] } } -
-- This informs Gradle to locate JNI libraries in the lib subdirectory. +}+
+This informs Gradle to locate JNI libraries in the lib subdirectory. +-
- In the dependencies section, include: --
- This line instructs Gradle to include .jar libraries in the resulting APK. -
++In the dependencies section, include: ++
+This line instructs Gradle to include .jar libraries in the resulting APK. +
-- task buildSwiftProject(type: Exec) { ++
- commandLine 'scd', +- At the end of build.gradle, insert the following custom Gradle task:
+++ + ++task buildSwiftProject(type: Exec) { - 'archive', '--type', 'android', + commandLine 'scd', - '--path', 'src/main/swift', + 'archive', '--type', 'android', - '--platform', 'android-arm64-v8a', + '--path', 'src/main/swift', - '--platform', 'android-x86_64' - } + '--platform', 'android-arm64-v8a', - tasks.whenTaskAdded { task -> + '--platform', 'android-x86_64' +} - if (task.name == 'assembleDebug' || task.name == 'assembleRelease') { +tasks.whenTaskAdded { task -> - task.dependsOn buildSwiftProject + if (task.name == 'assembleDebug' || task.name == 'assembleRelease') { - } + task.dependsOn buildSwiftProject } -+ +} + +Initialize Swift Runtime and Load JNI Library
++
+ +- In MainActivity.java, add Swift runtime initialization in the onCreate method:
+++ ++@Override -+Initialize Swift Runtime and Load JNI Library
--
+protected void onCreate(Bundle savedInstanceState) { -- In MainActivity.java, add Swift runtime initialization in the onCreate method:
--- // Continue with your activity code + -- @Override + super.onCreate(savedInstanceState); - protected void onCreate(Bundle savedInstanceState) { + setContentView(R.layout.activity_main); - super.onCreate(savedInstanceState); + try { - setContentView(R.layout.activity_main); + org.swift.swiftfoundation.SwiftFoundation.Initialize(this, false); - try { + } catch (Exception err) { - org.swift.swiftfoundation.SwiftFoundation.Initialize(this, false); + android.util.Log.e("Swift", "Can't initialize Swift Foundation: " + err.toString()); - } catch (Exception err) { + } - android.util.Log.e("Swift", "Can't initialize Swift Foundation: " + err.toString()); + // Continue with your activity code - } +} +++
- } -- Load the JNI library using:
++- ++System.loadLibrary("SwiftAndroidExample"); ++-
+- Load the JNI library using:
-Java Methods Calling Swift Implementation
+In your Android application, you can declare Java methods that serve as bridges to Swift code. The implementation of these methods will be written in Swift, allowing seamless integration between the two languages. Here's an example:
--- -- System.loadLibrary("SwiftAndroidExample"); -+++ ++public class MainActivity extends AppCompatActivity { --Java Methods Calling Swift Implementation
-In your Android application, you can declare Java methods that serve as bridges to Swift code. The implementation of these methods will be written in Swift, allowing seamless integration between the two languages. Here's an example:
- --- // ... Rest of your MainActivity code - } - -- public class MainActivity extends AppCompatActivity { + // Declare a native method in Java, with the implementation in Swift - // Declare a native method in Java, with the implementation in Swift + public native void printHelloWorld(); - public native void printHelloWorld(); + // This method is called from Swift code, and the result is sent as an input parameter - // This method is called from Swift code, and the result is sent as an input parameter + public void printText(String validationResult) { - public void printText(String validationResult) { + // Assuming headerTV is a TextView in your layout - // Assuming headerTV is a TextView in your layout + headerTV.setText(validationResult); + } - headerTV.setText(validationResult); - } + // ... Rest of your MainActivity code +} ++The Swift implementation of printHelloWorld and the Swift code calling printText will complete the interaction between Java and Swift, providing a seamless integration of functionalities in your Android application.
-The Swift implementation of printHelloWorld and the Swift code calling printText will complete the interaction between Java and Swift, providing a seamless integration of functionalities in your Android application.
+Swift Implementation for Java Methods
+The MainActivity_printHelloWorld function is annotated with @_silgen_name to set the native name for the function when called from Java. It takes the JNI environment (env) and the Java activity (activity) as parameters. Inside this function, you create a JObject wrapper for the Java activity and call the updateTasksList function to perform the desired interaction with the Java code.
-Swift Implementation for Java Methods
-The MainActivity_printHelloWorld function is annotated with @_silgen_name to set the native name for the function when called from Java. It takes the JNI environment (env) and the Java activity (activity) as parameters. Inside this function, you create a JObject wrapper for the Java activity and call the updateTasksList function to perform the desired interaction with the Java code.
+++ ++import Dispatch ---- } - -- import Dispatch +import Foundation - import Foundation +import Java - import Java +// Function to update tasks list in Java - // Function to update tasks list in Java +public func updateTasksList(activity: JObject) { - public func updateTasksList(activity: JObject) { + // Call the Java method "printText" with the message "Hello World!" - // Call the Java method "printText" with the message "Hello World!" + activity.call(method: "printText", "Hello World!") - activity.call(method: "printText", "Hello World!") +} - } +// Use @_silgen_name attribute to set native name for a function called from Java - // Use @_silgen_name attribute to set native name for a function called from Java +@_silgen_name("Java_com_example_swiftandroidexample_MainActivity_printHelloWorld") - @_silgen_name("Java_com_example_swiftandroidexample_MainActivity_printHelloWorld") +public func MainActivity_printHelloWorld( - public func MainActivity_printHelloWorld( + env: UnsafeMutablePointer<JNIEnv>, activity: JavaObject - env: UnsafeMutablePointer<JNIEnv>, activity: JavaObject +) { - ) { + // Create JObject wrapper for the activity object - // Create JObject wrapper for the activity object + let mainActivity = JObject(activity) - let mainActivity = JObject(activity) + // Call the Swift function to update tasks list in Java - // Call the Swift function to update tasks list in Java + updateTasksList(activity: mainActivity) - updateTasksList(activity: mainActivity) +} ++This Swift code demonstrates the integration of Swift functions with Java methods, allowing for bidirectional communication between Swift and Java in your Android application.
-This Swift code demonstrates the integration of Swift functions with Java methods, allowing for bidirectional communication between Swift and Java in your Android application.
+Run the Hello World App
+Run the Android Appusing Swift’s code like you would run any Android project in Android Studio, on Android Emulator/Physical device. You should be able to see Hello World.
-Run the Hello World App
-Run the Android Appusing Swift’s code like you would run any Android project in Android Studio, on Android Emulator/Physical device. You should be able to see Hello World.
+ - +Source Code: Please find the source code of Hello World App(Swift for Android) here
+ -Source Code: Please find the source code of Hello World App(Swift for Android) here
- -+Go Further
Ready to dive deeper? Here are some hand-picked resources covering various Swift features.
@@ -355,31 +355,64 @@Go Further
Implement RecyclerView using Swift PM libraries
-Swift for Android: How to use Swift-Crypto with Android Studio
-Using Swift PM libraries in the Android Studio projects
-