Skip to content

[core] Add nativeRefType to SharedRef#31776

Merged
lukmccall merged 6 commits intomainfrom
@lukmccall/core/add-native-ref-type
Oct 3, 2024
Merged

[core] Add nativeRefType to SharedRef#31776
lukmccall merged 6 commits intomainfrom
@lukmccall/core/add-native-ref-type

Conversation

@lukmccall
Copy link
Copy Markdown
Contributor

Why

Adds nativeRefType to SharedRef.
SharedRef's can now be checked on the JS side to ensure the native type is correct when passed across packages. For example, if you pass a SharedRef holding an image, the module should verify that it has not received a different type.

How

Added a new property called nativeRefType. In the future, we will probably add a field containing information about the native class.

Test Plan

  • bare-expo
    • iOS ✅
    • Android ✅
    • web ✅

@github-actions
Copy link
Copy Markdown
Contributor

CodeMention:

File Patterns Mentions
packages/expo-image/** @lukmccall, @tsapeta, @aleqsio
packages/expo-image-manipulator/** @lukmccall, @alanjhughes
packages/expo-modules-core/** @tsapeta, @Kudo, @lukmccall

Copy link
Copy Markdown
Contributor

@aleqsio aleqsio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the approach with essentially tagging the SharedRef.

One thought:
Would it maybe be possible to compute the tag based on the underlying native class?
If you create SharedRef(image), the nativeRefType would be UIImage on iOS and Drawable on Android, with the TS side code having an explicit check for both options.


Class(SharedString.self) {
Constructor {
SharedString("string")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this argument if we already override nativeRefType? Seems duplicative.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string here is a value of the reference, not the nativeRefType.

to native instances among different independent libraries.
*/
open class SharedRef<RefType>: SharedObject {
open class SharedRef<RefType>: SharedObject, AnySharedRef {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have a constructor like SharedRef("image", drawable) so that you can create refs without inheriting from SharedRef?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think providing the nativeRefType would be common. There aren't many objects that make sense to move between packages, so I don't think adding such a constructor would be necessary. Also, that gives you two different ways of providing the nativeRefType.

@lukmccall lukmccall force-pushed the @lukmccall/core/add-native-ref-type branch from aafe118 to 8d1f419 Compare October 3, 2024 12:58
@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Oct 3, 2024
@lukmccall lukmccall requested a review from tsapeta October 3, 2024 13:08
@expo-bot
Copy link
Copy Markdown
Collaborator

expo-bot commented Oct 3, 2024

The Pull Request introduced fingerprint changes against the base commit: e10d05f

Fingerprint diff
[
  {
    "op": "changed",
    "source": {
      "type": "dir",
      "filePath": "../../packages/expo-image-manipulator/android",
      "reasons": [
        "expoAutolinkingAndroid"
      ],
      "hash": "1a775d921077fd057d2a36b59ae17f85ed186b46"
    }
  },
  {
    "op": "changed",
    "source": {
      "type": "dir",
      "filePath": "../../packages/expo-image-manipulator/ios",
      "reasons": [
        "expoAutolinkingIos"
      ],
      "hash": "aa9a2923eace2f8861b663b5bc6f6b8baffe1541"
    }
  },
  {
    "op": "changed",
    "source": {
      "type": "dir",
      "filePath": "../../packages/expo-image/android",
      "reasons": [
        "expoAutolinkingAndroid"
      ],
      "hash": "44fd530d42c77f566613284bee8d98b72955afc4"
    }
  },
  {
    "op": "changed",
    "source": {
      "type": "dir",
      "filePath": "../../packages/expo-image/ios",
      "reasons": [
        "expoAutolinkingIos"
      ],
      "hash": "819f8520268619eb96ecb63bba4f545803cff264"
    }
  },
  {
    "op": "changed",
    "source": {
      "type": "dir",
      "filePath": "../../packages/expo-modules-core",
      "reasons": [
        "expoAutolinkingIos",
        "expoAutolinkingAndroid"
      ],
      "hash": "2fb8d1d120cc357d35c62fdfa99fdf52888c250b"
    }
  }
]

Generated by PR labeler 🤖

@lukmccall lukmccall merged commit 9ac73b2 into main Oct 3, 2024
@lukmccall lukmccall deleted the @lukmccall/core/add-native-ref-type branch October 3, 2024 15:40
@expo-bot
Copy link
Copy Markdown
Collaborator

expo-bot commented Oct 3, 2024

Hi there! 👋 I'm a bot whose goal is to ensure your contributions meet our guidelines.

I've found some issues in your pull request that should be addressed (click on them for more details) 👇

⚠️ Suggestion: Missing changelog entries


Your changes should be noted in the changelog, e.g.:
- Add nativeRefTypetoSharedRef ([#31776](https://github.com/expo/expo/pull/31776) by [@lukmccall](https://github.com/lukmccall))
Read Updating Changelogs guide and consider adding an appropriate entry to the following changelogs:


Generated by ExpoBot 🤖 against 9ab14b8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants