add some more native code
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
group = 'expo.modules.blueskyswissarmy'
|
||||
version = '0.6.0'
|
||||
|
||||
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
||||
apply from: expoModulesCorePlugin
|
||||
applyKotlinExpoModulesCorePlugin()
|
||||
useCoreDependencies()
|
||||
useExpoPublishing()
|
||||
|
||||
// If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
|
||||
// The Android SDK versions will be bumped from time to time in SDK releases and may introduce breaking changes in your module code.
|
||||
// Most of the time, you may like to manage the Android SDK versions yourself.
|
||||
def useManagedAndroidSdkVersions = false
|
||||
if (useManagedAndroidSdkVersions) {
|
||||
useDefaultAndroidSdkVersions()
|
||||
} else {
|
||||
buildscript {
|
||||
// Simple helper that allows the root project to override versions declared by this library.
|
||||
ext.safeExtGet = { prop, fallback ->
|
||||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
||||
}
|
||||
}
|
||||
project.android {
|
||||
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
||||
defaultConfig {
|
||||
minSdkVersion safeExtGet("minSdkVersion", 21)
|
||||
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "expo.modules.blueskyswissarmy"
|
||||
defaultConfig {
|
||||
versionCode 1
|
||||
versionName "0.6.0"
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<manifest>
|
||||
</manifest>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package expo.modules.blueskyswissarmy
|
||||
|
||||
import expo.modules.kotlin.modules.Module
|
||||
import expo.modules.kotlin.modules.ModuleDefinition
|
||||
|
||||
class ExpoBlueskySwissArmyModule : Module() {
|
||||
override fun definition() = ModuleDefinition {
|
||||
Name("ExpoBlueskySwissArmy")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"platforms": ["ios", "tvos", "android", "web"],
|
||||
"ios": {
|
||||
"modules": ["ExpoBlueskySwissArmyModule"]
|
||||
},
|
||||
"android": {
|
||||
"modules": ["expo.modules.blueskyswissarmy.ExpoBlueskySwissArmyModule"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
import {ExpoBlueskySwissArmyModule} from './src/ExpoBlueskySwissArmy'
|
||||
export {ExpoBlueskySwissArmyModule as SwissArmyKnife}
|
||||
@@ -0,0 +1,21 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'ExpoBlueskySwissArmy'
|
||||
s.version = '1.0.0'
|
||||
s.summary = 'A collection of native tools for Bluesky'
|
||||
s.description = 'A collection of native tools for Bluesky'
|
||||
s.author = ''
|
||||
s.homepage = 'https://github.com/bluesky-social/social-app'
|
||||
s.platforms = { :ios => '13.4', :tvos => '13.4' }
|
||||
s.source = { git: '' }
|
||||
s.static_framework = true
|
||||
|
||||
s.dependency 'ExpoModulesCore'
|
||||
|
||||
# Swift/Objective-C compatibility
|
||||
s.pod_target_xcconfig = {
|
||||
'DEFINES_MODULE' => 'YES',
|
||||
'SWIFT_COMPILATION_MODE' => 'wholemodule'
|
||||
}
|
||||
|
||||
s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
import ExpoModulesCore
|
||||
|
||||
public class ExpoBlueskySwissArmyModule: Module {
|
||||
func getDefaults(_ useAppGroup: Bool) -> UserDefaults? {
|
||||
if useAppGroup {
|
||||
return UserDefaults(suiteName: "group.app.bsky")
|
||||
} else {
|
||||
return UserDefaults.standard
|
||||
}
|
||||
}
|
||||
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("ExpoBlueskySwissArmy")
|
||||
|
||||
AsyncFunction("getStringValueAsync") { (key: String, useAppGroup: Bool) in
|
||||
let defaults = self.getDefaults(useAppGroup)
|
||||
|
||||
return defaults?.string(forKey: key)
|
||||
}
|
||||
|
||||
AsyncFunction("setStringValueAsync") { (key: String, value: String?, useAppGroup: Bool) in
|
||||
let defaults = self.getDefaults(useAppGroup)
|
||||
defaults?.setValue(value, forKey: key)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
type ExpoBlueskySwissArmyModuleType = {
|
||||
getStringValueAsync(
|
||||
key: string,
|
||||
useAppGroup?: boolean,
|
||||
): Promise<string | null>
|
||||
setStringValueAsync(
|
||||
key: string,
|
||||
value: string | null,
|
||||
useAppGroup?: boolean,
|
||||
): Promise<void>
|
||||
}
|
||||
|
||||
export const ExpoBlueskySwissArmyModule = {} as ExpoBlueskySwissArmyModuleType
|
||||
@@ -0,0 +1,8 @@
|
||||
export const ExpoBlueskySwissArmyModule = {
|
||||
getStringValueAsync(_: string, _?: boolean): Promise<string> {
|
||||
throw new Error('getStringValueAsync is not available on Android')
|
||||
},
|
||||
setStringValueAsync(_: string, _: string | null, _?: boolean): Promise<void> {
|
||||
throw new Error('setStringValueAsync is not available on Android')
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import {requireNativeModule} from 'expo-modules-core'
|
||||
|
||||
const NativeModule = requireNativeModule('ExpoBlueskySwissArmy')
|
||||
|
||||
export const ExpoBlueskySwissArmyModule = {
|
||||
getStringValueAsync(key: string, useAppGroup = false): Promise<string> {
|
||||
return NativeModule.getStringValueAsync(key, useAppGroup)
|
||||
},
|
||||
setStringValueAsync(
|
||||
key: string,
|
||||
value: string | null,
|
||||
useAppGroup = false,
|
||||
): Promise<void> {
|
||||
return NativeModule.setStringValueAsync(key, value, useAppGroup)
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export const ExpoBlueskySwissArmyModule = {
|
||||
getStringValueAsync(_: string, _?: boolean): Promise<string> {
|
||||
throw new Error('getStringValueAsync is not available on web')
|
||||
},
|
||||
setStringValueAsync(_: string, _: string | null, _?: boolean): Promise<void> {
|
||||
throw new Error('setStringValueAsync is not available on web')
|
||||
},
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
import React from 'react'
|
||||
|
||||
import {makeStarterPackLink} from 'lib/routes/links'
|
||||
import {useSetCurrentStarterPack} from 'state/preferences/starter-pack'
|
||||
import {useUsedStarterPacks} from 'state/preferences/used-starter-packs'
|
||||
import GooglePlayReferrer from '../../../modules/expo-google-play-referrer'
|
||||
|
||||
export function useStarterPackEntry() {
|
||||
const [ready, setReady] = React.useState(false)
|
||||
const setCurrentStarterPack = useSetCurrentStarterPack()
|
||||
const usedStarterPacks = useUsedStarterPacks()
|
||||
|
||||
React.useEffect(() => {
|
||||
if (ready) return
|
||||
;(async () => {
|
||||
const res = await GooglePlayReferrer.getReferrerInfoAsync()
|
||||
|
||||
if (res && res.installReferrer) {
|
||||
// The `utm_content` parameter should be `starterpack-<name>-rkey>`. Let's try to get it from the parameters
|
||||
// and create a URI for it if it's valid.
|
||||
const parts = res.installReferrer.split('&')
|
||||
const starterPackSource = parts
|
||||
.find(part => part.startsWith('utm_content='))
|
||||
?.split('=')[1]
|
||||
const sourceParts = starterPackSource?.split('-')
|
||||
|
||||
if (sourceParts?.length === 3 && sourceParts[0] === 'starterpack') {
|
||||
// Android doesn't clear the referrer info for a total of 90 days. We want to make sure that we don't
|
||||
// retrigger this on accident.
|
||||
// We won't actually set `lastUsedUri` until a _successful_ use of the starter pack, meaning a new account
|
||||
// has actually completed onboarding with the given starter pack.
|
||||
const uri = makeStarterPackLink(sourceParts[1], sourceParts[2])
|
||||
if (!usedStarterPacks?.includes(uri)) {
|
||||
setCurrentStarterPack({
|
||||
uri: makeStarterPackLink(sourceParts[1], sourceParts[2]),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
setReady(true)
|
||||
})()
|
||||
}, [ready, setCurrentStarterPack, usedStarterPacks])
|
||||
|
||||
return ready
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import React from 'react'
|
||||
|
||||
export function useStarterPackEntry() {
|
||||
const [ready, setReady] = React.useState(false)
|
||||
|
||||
React.useEffect(() => {
|
||||
;(async () => {
|
||||
setReady(true)
|
||||
})()
|
||||
}, [])
|
||||
|
||||
return ready
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import React from 'react'
|
||||
|
||||
import {makeStarterPackLink} from 'lib/routes/links'
|
||||
import {isAndroid} from 'platform/detection'
|
||||
import {useSetCurrentStarterPack} from 'state/preferences/starter-pack'
|
||||
import {useUsedStarterPacks} from 'state/preferences/used-starter-packs'
|
||||
import {SwissArmyKnife} from '../../../modules/expo-bluesky-swiss-army'
|
||||
import GooglePlayReferrer from '../../../modules/expo-google-play-referrer'
|
||||
|
||||
export function useStarterPackEntry() {
|
||||
const [ready, setReady] = React.useState(false)
|
||||
const setCurrentStarterPack = useSetCurrentStarterPack()
|
||||
const usedStarterPacks = useUsedStarterPacks()
|
||||
|
||||
React.useEffect(() => {
|
||||
if (ready) return
|
||||
;(async () => {
|
||||
let uri: string | null | undefined
|
||||
|
||||
if (isAndroid) {
|
||||
const res = await GooglePlayReferrer.getReferrerInfoAsync()
|
||||
|
||||
if (res && res.installReferrer) {
|
||||
const parts = res.installReferrer.split('&')
|
||||
const starterPackSource = parts
|
||||
.find(part => part.startsWith('utm_content='))
|
||||
?.split('=')[1]
|
||||
const sourceParts = starterPackSource?.split('-')
|
||||
if (sourceParts?.length === 3 && sourceParts[0] === 'starterpack') {
|
||||
uri = makeStarterPackLink(sourceParts[1], sourceParts[2])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
uri = await SwissArmyKnife.getStringValueAsync('starterPackUri', true)
|
||||
}
|
||||
|
||||
if (uri && !usedStarterPacks?.includes(uri)) {
|
||||
setCurrentStarterPack({
|
||||
uri,
|
||||
})
|
||||
}
|
||||
|
||||
setReady(true)
|
||||
})()
|
||||
}, [ready, setCurrentStarterPack, usedStarterPacks])
|
||||
|
||||
return ready
|
||||
}
|
||||
Reference in New Issue
Block a user