Skip to content

Commit d2cf0d1

Browse files
committed
feat: support visionOS
1 parent 08e8180 commit d2cf0d1

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

packages/async-storage/AsyncStorage.podspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ Pod::Spec.new do |s|
1010
s.license = package["license"]
1111
s.authors = package["author"]
1212

13-
s.platforms = { :ios => min_ios_version_supported, :osx => "12.0" }
13+
s.platforms = { :ios => "13.0", :osx => "12.0", :visionos => "1.0" }
1414
s.source = { :git => "https://github.com/react-native-async-storage/async-storage.git", :tag => "#{s.version}" }
1515
s.resource_bundles = { "AsyncStorage_resources" => "apple/PrivacyInfo.xcprivacy" }
1616

1717
s.source_files = "apple/**/*.{h,m,mm,cpp,swift}"
1818
s.private_header_files = "apple/**/*.h"
1919
s.swift_version = "5.9.2"
20-
s.vendored_frameworks = "apple/Frameworks/SharedAsyncStorage.xcframework"
20+
21+
s.ios.vendored_frameworks = "apple/Frameworks/SharedAsyncStorage.xcframework"
22+
s.osx.vendored_frameworks = "apple/Frameworks/SharedAsyncStorage.xcframework"
2123

2224

2325
install_modules_dependencies(s)

packages/async-storage/apple/AsyncStorage.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#import "AsyncStorage.h"
2+
#import "RNCAsyncStorage.h" // legacy storage
23

4+
#if !TARGET_OS_VISION
35
#import "AsyncStorage-Swift.h"
4-
#import "RNCAsyncStorage.h" // legacy storage
6+
#endif
57

68
@implementation AsyncStorage
79
RCT_EXPORT_MODULE(RNAsyncStorage)
810

11+
#if !TARGET_OS_VISION // visionos not supported for SharedStorage
912
RCT_EXPORT_METHOD(getValues
1013
: (nonnull NSString *)dbName keys
1114
: (nonnull NSArray *)keys resolve
@@ -57,6 +60,7 @@ @implementation AsyncStorage
5760
RNStorage *db = [StorageRegistry.shared getRNStorageWithDbName:dbName];
5861
[db allKeysWithResolver:resolve rejecter:reject];
5962
}
63+
#endif
6064

6165
#pragma mark - Legacy Storage
6266

packages/async-storage/apple/storage/RNStorage.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
#if !os(visionOS) // not supported
12
import React
23
import SharedAsyncStorage
34

4-
55
@objc
66
public class RNStorage: NSObject {
77
private let db: SharedStorage
8-
8+
99
init(db: SharedStorage) {
1010
self.db = db
1111
}
@@ -118,3 +118,4 @@ extension NSError {
118118
return nil
119119
}
120120
}
121+
#endif

packages/async-storage/apple/storage/StorageRegistry.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !os(visionOS) // not supported
12
import SharedAsyncStorage
23

34
/**
@@ -49,3 +50,4 @@ public class StorageRegistry: NSObject {
4950
}()
5051
}
5152
}
53+
#endif

packages/async-storage/src/createAsyncStorage.native.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@ import NativeAsyncStorage, {
33
type Spec as NativeAsyncStorageSpec,
44
} from "./native-module/NativeAsyncStorage";
55
import { AsyncStorageError } from "./AsyncStorageError";
6+
import { Platform } from "react-native";
7+
8+
let visionOsWarned = false;
69

710
/**
811
* Creates a new AsyncStorage instance bound to a given database name.
912
* @param databaseName - The name of the database to open or create.
1013
*/
1114
export function createAsyncStorage(databaseName: string): AsyncStorage {
15+
if (Platform.OS === "ios" && Platform.isVision) {
16+
if (!visionOsWarned) {
17+
visionOsWarned = true;
18+
// eslint-disable-next-line
19+
console.warn(
20+
"[AsyncStorage] Warning: Creating custom storages is not supported on visionOS. Falling back to the legacy implementation."
21+
);
22+
}
23+
return getLegacyStorage();
24+
}
25+
1226
return new AsyncStorageImpl(databaseName);
1327
}
1428

0 commit comments

Comments
 (0)