Skip to content

Commit

Permalink
- Add basic UNNotificationCenter support
Browse files Browse the repository at this point in the history
- Split UIKit implementations into separate files
- Fix .onOpenURL when Activity is singleTop
  • Loading branch information
aabewhite committed Sep 4, 2024
1 parent 5afbc33 commit 430d9bb
Show file tree
Hide file tree
Showing 9 changed files with 1,422 additions and 876 deletions.
8 changes: 4 additions & 4 deletions Sources/SkipUI/SkipUI/Containers/PresentationRoot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// as published by the Free Software Foundation https://fsf.org

#if SKIP
import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.ExperimentalLayoutApi
Expand Down Expand Up @@ -97,13 +97,13 @@ import androidx.compose.ui.platform.LocalLayoutDirection

@Composable func launchUIApplicationActivity() {
// Modern Skip projects will set the launch activity in Main.kt. This function exists for older projects
guard UIApplication.shared.launchActivity == nil else {
guard UIApplication.shared.androidActivity == nil else {
return
}
var context: Context? = LocalContext.current
var activity: Activity? = nil
var activity: AppCompatActivity? = nil
while context != nil {
if let a = context as? Activity {
if let a = context as? AppCompatActivity {
activity = a
break
} else if let w = context as? ContextWrapper {
Expand Down
37 changes: 32 additions & 5 deletions Sources/SkipUI/SkipUI/System/UserActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

import Foundation
#if SKIP
import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import android.content.Intent
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.core.util.Consumer
#endif

extension View {
Expand All @@ -31,10 +36,26 @@ extension View {
public func onOpenURL(perform action: @escaping (URL) -> Void) -> some View {
#if SKIP
return ComposeModifierView(targetView: self) { context in
guard let activity = LocalContext.current as? Activity, let intent = activity.intent, intent.action == Intent.ACTION_VIEW else {
guard let activity = LocalContext.current as? AppCompatActivity else {
return ComposeResult.ok
}
guard let dataString = intent.dataString, let url = URL(string: dataString) else {
let newIntent = remember { mutableStateOf<Intent?>(nil) }
let listener = remember {
let listener = OnNewIntentListener(newIntent)
activity.addOnNewIntentListener(listener)
return listener
}
DisposableEffect(true) {
onDispose {
activity.removeOnNewIntentListener(listener)
}
}

guard let intent = newIntent.value ?? activity.intent else {
return ComposeResult.ok
}
newIntent.value = nil
guard intent.action == Intent.ACTION_VIEW, let dataString = intent.dataString, let url = URL(string: dataString) else {
return ComposeResult.ok
}
SideEffect {
Expand All @@ -52,8 +73,14 @@ extension View {
}
}

#if !SKIP
import struct Foundation.URL
#if SKIP
struct OnNewIntentListener : Consumer<Intent> {
let newIntent: MutableState<Intent?>

override func accept(value: Intent) {
newIntent.value = value
}
}
#endif

#if false
Expand Down
Loading

0 comments on commit 430d9bb

Please sign in to comment.