Skip to content

fix(android): correct long term access directory picker response #823

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

Conversation

OldStager01
Copy link
Contributor

PR: Rename 'status' key to 'bookmarkStatus' in Android directory picker response

Description

This PR standardizes the response format for directory picking on Android by renaming the status key to bookmarkStatus when requestLongTermAccess is set to true. This change ensures consistency across platforms and aligns with the expected type definitions.

Changes Made

  • Modified processDirectoryPickerResult() method in RNDocumentPickerModule.kt to use bookmarkStatus instead of status in the response object when handling long-term directory access permissions
  • Updated releaseLongTermAccess() method to also use bookmarkStatus instead of status in the response for consistency

Technical Details

The changes were made in two specific locations in packages/document-picker/android/src/main/java/com/reactnativedocumentpicker/RNDocumentPickerModule.kt:

  1. In the processDirectoryPickerResult() method (~line 392-399):

    - map.putString("status", "success")
    + map.putString("bookmarkStatus", "success")
    - map.putString("status", "error")
    + map.putString("bookmarkStatus", "error")
  2. In the releaseLongTermAccess() method (~line 352-358):

    - result.putString("status", "success")
    + result.putString("bookmarkStatus", "success")
    - result.putString("status", "error")
    + result.putString("bookmarkStatus", "error")

Example Usage

When using pickDirectory() with long-term access:

const response = await pickDirectory({ requestLongTermAccess: true });

Previous Response Format (Incorrect)

{
  "bookmark": "Y29udGVudDovL2NvbS5hbmRyb2lkLmV4dGVybmFsc3RvcmFnZS5kb2N1bWVudHMvdHJlZS9wcmltYXJ5JTNBRG93bmxvYWQlMkZRdWljayUyMFNoYXJl",
  "status": "success",
  "uri": "content://com.android.externalstorage.documents/tree/primary%3ADownload%2FQuick%20Share"
}

Fixed Response Format (Correct)

{
  "bookmark": "Y29udGVudDovL2NvbS5hbmRyb2lkLmV4dGVybmFsc3RvcmFnZS5kb2N1bWVudHMvdHJlZS9wcmltYXJ5JTNBRG93bmxvYWQlMkZRdWljayUyMFNoYXJl",
  "bookmarkStatus": "success",
  "uri": "content://com.android.externalstorage.documents/tree/primary%3ADownload%2FQuick%20Share"
}

Testing

  • Verified the response now includes bookmarkStatus instead of status when requestLongTermAccess is true
  • Tested both success and error cases to ensure all relevant fields are updated correctly

Impact

This change ensures consistent naming conventions, improving maintainability and cross-platform compatibility by aligning the Android implementation with the expected type definitions used across the library.

- Updated the key from "status" to "bookmarkStatus" in Android to ensure consistency
  across platforms.
- According to the type definitions, "bookmarkStatus" was the expected key, and this change
  aligns the implementation accordingly.
- This update standardizes the key across implementations, reducing potential confusion for
  developers and improving cross-platform compatibility.

No functional changes beyond renaming the key.
Copy link

changeset-bot bot commented May 5, 2025

🦋 Changeset detected

Latest commit: 6b030f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@react-native-documents/picker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vonovak vonovak changed the title fix(android): replace 'status' with 'bookmarkStatus' for unified response key fix(android): correct long term access directory picker response May 5, 2025
@vonovak vonovak merged commit c7166b1 into react-native-documents:main May 5, 2025
4 checks passed
@vonovak
Copy link
Member

vonovak commented May 5, 2025

Thank you for the PR!

@OldStager01
Copy link
Contributor Author

You're welcome! Glad to contribute. Let me know if there's anything else I can help with.

Thank you for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants