Skip to content
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

feat: add responsive layouts #273

Merged
merged 8 commits into from
Nov 11, 2024
Merged

feat: add responsive layouts #273

merged 8 commits into from
Nov 11, 2024

Conversation

HayesGordon
Copy link
Contributor

@HayesGordon HayesGordon commented Nov 7, 2024

This exposes Fit.Layout and layoutScaleFactor for Rive React Native.

iOS handles layoutScaleFactor with a value of "-1" to be not set (null). In which case iOS handles the scale factor automatically.

Android does the same, but when layoutScaleFactor is null. Android is more limited in it's pixel density calculations, as we cannot automatically subscribe to changes.

That means in React Native land, users will need to manage the density themselves if they want it to respond to device density changes consistently across Android and iOS - because iOS manages it better and we can't do more for Android. This will need to be a documentation effort

The current implementation attempts to handle both situations, where the value can either be null or -1.


EDIT: Resolved the below!

However, on React Native we have the opposite problem. Where Android can't take a null but iOS can through the bindings 🫠

I'm leaning towards updating the JS to default send -1 if the prop is null. But interested to hear your thoughts, or maybe I missed some way to handle this.

@@ -104,6 +106,8 @@
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
ED2971642150620600B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS12.0.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; };
F8AA4CA32C0F3FDB00C1A5FF /* runtime_nested_inputs.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = runtime_nested_inputs.riv; sourceTree = "<group>"; };
F8E2789D2CDCD6A200FAA8EF /* layouts_demo.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = layouts_demo.riv; sourceTree = "<group>"; };
F8E278A12CDCDAFA00FAA8EF /* layout_test.riv */ = {isa = PBXFileReference; lastKnownFileType = file; name = layout_test.riv; path = ../../../../../../rive/rive/packages/runtime_wasm/js/examples/_frameworks/layout_example/assets/layout_test.riv; sourceTree = "<group>"; };
Copy link
Contributor

@lancesnider lancesnider Nov 7, 2024

Choose a reason for hiding this comment

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

This is causing an error. It looks like it's pointing to a file on your local machine.

@lancesnider
Copy link
Contributor

This isn't a bug, but it might look like a bug to a user. On the example if you select Fit.Layout, it looks like this:

Screenshot 2024-11-07 at 9 06 16 AM

This is because this is an old file that doesn't actually have a layout. Maybe we should add one? If you have the .rev, I can do that.

@HayesGordon
Copy link
Contributor Author

This isn't a bug, but it might look like a bug to a user. On the example if you select Fit.Layout, it looks like this:

Screenshot 2024-11-07 at 9 06 16 AM

This is because this is an old file that doesn't actually have a layout. Maybe we should add one? If you have the .rev, I can do that.

Nice catch. I don't have the .rev, but we can use any example! If you have one to commit to this PR then let's do, otherwise, let's get this feature out and update the sample app later.

Copy link

@dskuza dskuza left a comment

Choose a reason for hiding this comment

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

This looks good to me! Just pointing one small thing out, and a question about another (specific to iOS).

Comment on lines 727 to 737
PRODUCT_BUNDLE_IDENTIFIER = com.example.rivereactnative;
PRODUCT_BUNDLE_IDENTIFIER = gordon.example.rivereactnative;
Copy link

Choose a reason for hiding this comment

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

Probably fine, just calling this out as a thing that's been committed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I forgot this, will remove

@@ -41,6 +41,8 @@ class RiveReactNativeView: RCTView, RivePlayerDelegate, RiveStateMachineDelegate

@objc var fit: String?

@objc var layoutScaleFactor: NSNumber = -1.0 // -1.0 will inform the iOS runtime to determine the correct scale factor automatically
Copy link

Choose a reason for hiding this comment

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

This type is a Double in Swift (and likely ObjC by interop). What's the decision behind using NSNumber?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Double doesn't work for nullable(optional) values in these bindings: https://reactnative.dev/docs/legacy/native-modules-ios#argument-types

@@ -99,6 +101,10 @@ class RiveReactNativeView: RCTView, RivePlayerDelegate, RiveStateMachineDelegate
if (changedProps.contains("alignment")) {
viewModel?.alignment = convertAlignment(alignment)
}

if (changedProps.contains("layoutScaleFactor")) {
viewModel?.layoutScaleFactor = layoutScaleFactor.doubleValue
Copy link

Choose a reason for hiding this comment

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

Ah, usage is here as a double value. But, still curious!

@@ -6,6 +6,7 @@ @interface RCT_EXTERN_MODULE(RiveReactNativeViewManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(resourceName, NSString)
RCT_EXPORT_VIEW_PROPERTY(url, NSString)
RCT_EXPORT_VIEW_PROPERTY(fit, NSString)
RCT_EXPORT_VIEW_PROPERTY(layoutScaleFactor, NSNumber)
Copy link

Choose a reason for hiding this comment

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

I'm assuming this has something to do with using NSNumber over Double?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup! In one of the other comments I linked to the reference docs

@HayesGordon HayesGordon merged commit 8e1f2c9 into main Nov 11, 2024
1 check passed
@HayesGordon HayesGordon deleted the add-responsive-layouts branch November 11, 2024 10:17
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.

3 participants