Repository navigation
feat: React Native SDK update for version 1.2.0-rc.0 #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a87d96a
chore: update React Native SDK to 0.34.0
ChiragAgg5k fea8440
chore: update React Native SDK to 0.34.0
ChiragAgg5k 3e227da
chore: update React Native SDK to 0.35.0
ChiragAgg5k 6a88b25
chore: merge main into dev for the 0.35.0 release
ChiragAgg5k 39d456d
docs: state the SDK targets Appwrite server version 2.0.x
ChiragAgg5k 4ae0583
fix: regenerate with the latest sdk-generator and add auto image gravity
ChiragAgg5k a8981f6
chore: update React Native SDK to 1.0.0
ChiragAgg5k 9d31879
chore: merge main into dev for the 1.0.0 release
ChiragAgg5k 9c92713
docs: scope the empty-string check to path parameters
ChiragAgg5k fc1f46f
docs: state the 2.2.x server target in the README
bee513e
chore: update React Native SDK to 1.1.0
ChiragAgg5k 70116a9
chore: merge main into dev for the 1.1.0 release
ChiragAgg5k 538feb7
Merge remote-tracking branch 'origin/dev' into dev
ArnabChatterjee20k f405561
chore: update React Native SDK to 1.2.0-rc.0
ArnabChatterjee20k 8e18cec
Merge remote-tracking branch 'origin/dev' into dev
ArnabChatterjee20k 8a6be11
chore: update React Native SDK to 1.2.0-rc.0
ArnabChatterjee20k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| root = true | ||
|
|
||
| [*.{kt,kts}] | ||
| ktlint_code_style = ktlint_official | ||
| ktlint_standard_annotation = disabled | ||
| ktlint_standard_argument-list-wrapping = disabled | ||
| ktlint_standard_blank-line-before-declaration = disabled | ||
| ktlint_standard_blank-line-between-when-conditions = disabled | ||
| ktlint_standard_chain-method-continuation = disabled | ||
| ktlint_standard_class-signature = disabled | ||
| ktlint_standard_function-expression-body = disabled | ||
| ktlint_standard_function-signature = disabled | ||
| ktlint_standard_function-start-of-body-spacing = disabled | ||
| ktlint_standard_if-else-bracing = disabled | ||
| ktlint_standard_if-else-wrapping = disabled | ||
| ktlint_standard_max-line-length = disabled | ||
| ktlint_standard_multiline-expression-wrapping = disabled | ||
| ktlint_standard_multiline-if-else = disabled | ||
| ktlint_standard_no-blank-line-before-rbrace = disabled | ||
| ktlint_standard_no-blank-line-in-list = disabled | ||
| ktlint_standard_no-empty-first-line-in-class-body = disabled | ||
| ktlint_standard_no-line-break-before-assignment = disabled | ||
| ktlint_standard_no-wildcard-imports = disabled | ||
| ktlint_standard_parameter-list-wrapping = disabled | ||
| ktlint_standard_spacing-between-declarations-with-annotations = disabled | ||
| ktlint_standard_spacing-between-declarations-with-comments = disabled | ||
| ktlint_standard_string-template = disabled | ||
| ktlint_standard_trailing-comma-on-call-site = disabled | ||
| ktlint_standard_trailing-comma-on-declaration-site = disabled | ||
| ktlint_standard_when-entry-bracing = disabled | ||
| ktlint_standard_wrapping = disabled | ||
|
|
||
| [**/Channel.kt] | ||
| # Marker types intentionally use leading underscores to distinguish channel states. | ||
| ktlint_standard_class-naming = disabled | ||
|
|
||
| [**/models/*.kt] | ||
| # Model imports follow schema property order so generated declarations stay deterministic. | ||
| ktlint_standard_import-ordering = disabled |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // The native half of Push on Android: background delivery that survives the process being | ||
| // killed, a reboot and an app update, shared with the Appwrite Android SDK. | ||
| def safeExtGet(prop, fallback) { | ||
| rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||
| } | ||
|
|
||
| apply plugin: "com.android.library" | ||
| apply plugin: "kotlin-android" | ||
|
|
||
| android { | ||
| namespace "io.appwrite.reactnative" | ||
| compileSdkVersion safeExtGet("compileSdkVersion", 35) | ||
|
|
||
| defaultConfig { | ||
| minSdkVersion safeExtGet("minSdkVersion", 24) | ||
| targetSdkVersion safeExtGet("targetSdkVersion", 35) | ||
| // R8 rules for the bundled MQTT client, applied to the app. | ||
| consumerProguardFiles "consumer-rules.pro" | ||
| } | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_17 | ||
| targetCompatibility JavaVersion.VERSION_17 | ||
| } | ||
|
|
||
| kotlinOptions { | ||
| jvmTarget = "17" | ||
| } | ||
| } | ||
|
|
||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation "com.facebook.react:react-android" | ||
| implementation "com.hivemq:hivemq-mqtt-client-shaded:1.3.6" | ||
| implementation "androidx.core:core-ktx:1.13.1" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Push: rules applied to apps that shrink with R8. | ||
| # | ||
| # The shaded HiveMQ MQTT client relocates Netty and JCTools under | ||
| # com.hivemq.client.internal.shaded. Netty references optional classes that are never loaded | ||
| # on Android: native transports, the HTTP/WebSocket codecs, proxy handlers, alternative TLS | ||
| # providers (tcnative, BouncyCastle, Conscrypt, Jetty ALPN) and logging backends. | ||
| -dontwarn com.hivemq.client.internal.shaded.io.netty.channel.epoll.** | ||
| -dontwarn com.hivemq.client.internal.shaded.io.netty.channel.kqueue.** | ||
| -dontwarn com.hivemq.client.internal.shaded.io.netty.handler.codec.http.** | ||
| -dontwarn com.hivemq.client.internal.shaded.io.netty.handler.proxy.** | ||
| -dontwarn com.hivemq.client.internal.shaded.io.netty.internal.tcnative.** | ||
| -dontwarn org.bouncycastle.** | ||
| -dontwarn org.conscrypt.** | ||
| -dontwarn org.eclipse.jetty.** | ||
| -dontwarn org.apache.log4j.** | ||
| -dontwarn org.apache.logging.log4j.** | ||
| -dontwarn org.slf4j.** | ||
| -dontwarn reactor.blockhound.** | ||
|
|
||
| # Netty and JCTools reach their own fields by name, through atomic field updaters and Unsafe offsets. | ||
| -keepclassmembernames class com.hivemq.client.internal.shaded.io.netty.** { <fields>; } | ||
| -keepclassmembers class com.hivemq.client.internal.shaded.org.jctools.** { <fields>; } | ||
|
|
||
| # Netty's leak detector looks these methods up by name when its classes load. | ||
| -keepclassmembers class com.hivemq.client.internal.shaded.io.netty.buffer.AbstractByteBufAllocator { *** toLeakAwareBuffer(...); } | ||
| -keepclassmembers class com.hivemq.client.internal.shaded.io.netty.buffer.AdvancedLeakAwareByteBuf { *** recordLeakNonRefCountingOperation(...); } | ||
| -keepclassmembers class com.hivemq.client.internal.shaded.io.netty.util.ReferenceCountUtil { *** touch(...); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> | ||
| <!-- Background Push delivery (subscribe(background = true)): scheduled runs that reconnect | ||
| under a short wakelock, on the current network, and resume after a reboot. Apps can also | ||
| declare SCHEDULE_EXACT_ALARM (punctual runs) and REQUEST_IGNORE_BATTERY_OPTIMIZATIONS | ||
| (a direct exemption prompt); both are optional and subject to Google Play policy. --> | ||
| <uses-permission android:name="android.permission.WAKE_LOCK" /> | ||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
| <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | ||
| <!-- Foreground-service background Push delivery (Push.setForeground). Apps that never enable it can | ||
| remove PushService and these two permissions with tools:node="remove". --> | ||
| <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> | ||
| <uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" /> | ||
|
|
||
| <application> | ||
| <service | ||
| android:name="io.appwrite.services.PushService" | ||
| android:exported="false" | ||
| android:foregroundServiceType="remoteMessaging" | ||
| android:stopWithTask="false" /> | ||
| <service | ||
| android:name="io.appwrite.services.PushJobService" | ||
| android:exported="false" | ||
| android:permission="android.permission.BIND_JOB_SERVICE" /> | ||
| <receiver | ||
| android:name="io.appwrite.services.PushAlarmReceiver" | ||
| android:exported="false" /> | ||
| <receiver | ||
| android:name="io.appwrite.services.PushBootReceiver" | ||
| android:exported="true"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.BOOT_COMPLETED" /> | ||
| <action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> | ||
| </intent-filter> | ||
| </receiver> | ||
| </application> | ||
|
|
||
| </manifest> |
6 changes: 6 additions & 0 deletions
6
android/src/main/java/io/appwrite/exceptions/AppwriteException.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package io.appwrite.exceptions | ||
|
|
||
| /** A push error. When the broker explained a refusal or a disconnect, that is its message. */ | ||
| class AppwriteException( | ||
| override val message: String? = null, | ||
| ) : Exception(message) |
31 changes: 31 additions & 0 deletions
31
android/src/main/java/io/appwrite/reactnative/AppwriteCookiesModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package io.appwrite.reactnative | ||
|
|
||
| import android.webkit.CookieManager | ||
| import com.facebook.react.bridge.Promise | ||
| import com.facebook.react.bridge.ReactApplicationContext | ||
| import com.facebook.react.bridge.ReactContextBaseJavaModule | ||
| import com.facebook.react.bridge.ReactMethod | ||
|
|
||
| class AppwriteCookiesModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { | ||
| override fun getName(): String = NAME | ||
|
|
||
| @ReactMethod | ||
| fun session(url: String, project: String, promise: Promise) { | ||
| val name = "a_session_$project" | ||
| try { | ||
| val value = CookieManager.getInstance().getCookie(url) | ||
| ?.split(";") | ||
| ?.map { it.trim() } | ||
| ?.firstOrNull { it.substringBefore("=") == name } | ||
| ?.substringAfter("=") | ||
| promise.resolve(value) | ||
| } catch (e: Exception) { | ||
| promise.reject(ERROR_CODE, e.message, e) | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| const val NAME = "AppwriteCookies" | ||
| private const val ERROR_CODE = "appwrite_cookies" | ||
| } | ||
| } |
127 changes: 127 additions & 0 deletions
127
android/src/main/java/io/appwrite/reactnative/AppwritePushModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| package io.appwrite.reactnative | ||
|
|
||
| import android.util.Base64 | ||
| import com.facebook.react.bridge.Arguments | ||
| import com.facebook.react.bridge.Promise | ||
| import com.facebook.react.bridge.ReactApplicationContext | ||
| import com.facebook.react.bridge.ReactContextBaseJavaModule | ||
| import com.facebook.react.bridge.ReactMethod | ||
| import com.facebook.react.modules.core.DeviceEventManagerModule | ||
| import io.appwrite.services.PushBridge | ||
| import io.appwrite.services.PushMessage | ||
|
|
||
| /** | ||
| * The React Native side of [PushBridge]: the SDK's `Push` hosts its background subscriptions | ||
| * here on Android, and receives their messages and errors as events. | ||
| * | ||
| * [emit] sends an event to JS; tests replace it to observe what JS would receive. | ||
| */ | ||
| class AppwritePushModule internal constructor( | ||
| private val reactContext: ReactApplicationContext, | ||
| private val emit: (String, Map<String, Any?>) -> Unit, | ||
| ) : ReactContextBaseJavaModule(reactContext) { | ||
| constructor(reactContext: ReactApplicationContext) : this( | ||
| reactContext, | ||
| { event, body -> | ||
| if (reactContext.hasActiveReactInstance()) { | ||
| reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) | ||
| .emit(event, Arguments.makeNativeMap(body)) | ||
| } | ||
| }, | ||
| ) | ||
|
|
||
| private val bridge = PushBridge( | ||
| reactContext, | ||
| object : PushBridge.Events { | ||
| override fun onMessage(subscriptionId: String, message: PushMessage, ackToken: String) = emit( | ||
| MESSAGE_EVENT, | ||
| mapOf( | ||
| "id" to subscriptionId, | ||
| "topic" to message.topic, | ||
| "payload" to Base64.encodeToString(message.payload, Base64.NO_WRAP), | ||
| "qos" to message.qos, | ||
| "ackToken" to ackToken, | ||
| ), | ||
| ) | ||
|
|
||
| override fun onError(message: String) = emit(ERROR_EVENT, mapOf("message" to message)) | ||
| }, | ||
| ) | ||
|
|
||
| override fun getName(): String = NAME | ||
|
|
||
| // Resolves once the connection is up and every filter is subscribed, or rejects with why not. | ||
| @ReactMethod | ||
| fun host(config: String, subscriptions: String, promise: Promise) { | ||
| try { | ||
| bridge.host(config, subscriptions) { error -> | ||
| if (error == null) { | ||
| promise.resolve(null) | ||
| } else { | ||
| promise.reject(ERROR_CODE, error) | ||
| } | ||
| } | ||
| } catch (e: Exception) { | ||
| promise.reject(ERROR_CODE, e.message, e) | ||
| } | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun ack(token: String) = bridge.ack(token) | ||
|
|
||
| @ReactMethod | ||
| fun release(promise: Promise) = settle(promise) { | ||
| bridge.release() | ||
| null | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun stop(promise: Promise) = settle(promise) { | ||
| bridge.stop() | ||
| null | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun setForeground(enabled: Boolean, promise: Promise) = settle(promise) { | ||
| bridge.setForeground(enabled) | ||
| null | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun hasSaved(promise: Promise) = settle(promise) { bridge.hasSaved() } | ||
|
|
||
| @ReactMethod | ||
| fun resume(promise: Promise) = settle(promise) { | ||
| bridge.resume() | ||
| null | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun setErrorCallback(registered: Boolean, promise: Promise) = settle(promise) { bridge.setErrorCallback(registered) } | ||
|
|
||
| @ReactMethod | ||
| fun defaultClientId(authMethod: String, credential: String, promise: Promise) = | ||
| settle(promise) { bridge.defaultClientId(authMethod, credential) } | ||
|
|
||
| // Required by NativeEventEmitter; events are emitted whether or not anyone listens. | ||
| @ReactMethod | ||
| fun addListener(eventName: String) = Unit | ||
|
|
||
| @ReactMethod | ||
| fun removeListeners(count: Double) = Unit | ||
|
|
||
| private fun settle(promise: Promise, block: () -> Any?) { | ||
| try { | ||
| promise.resolve(block()) | ||
| } catch (e: Exception) { | ||
| promise.reject(ERROR_CODE, e.message, e) | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| const val NAME = "AppwritePush" | ||
| const val MESSAGE_EVENT = "AppwritePushMessage" | ||
| const val ERROR_EVENT = "AppwritePushError" | ||
| private const val ERROR_CODE = "appwrite_push" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.