Skip to content

Conversation

@jakub-trzebiatowski
Copy link
Contributor

Summary:

Extract the typeface-finding logic to findEffectiveTypeface extension methods.

Changelog:

[INTERNAL] [CHANGED] - Extract the typeface-finding logic to findEffectiveTypeface

Test Plan:

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 29, 2024
@jakub-trzebiatowski
Copy link
Contributor Author

This is not a very big deal, but helps me later down the road in my work on #42602

@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jan 29, 2024
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 17,066,844 +12
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 20,450,434 +2
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: cfc0ba0
Branch: main

val fontWeight: Int
}

fun FontAttributeProvider.findEffectiveTypeface(
Copy link
Contributor

Choose a reason for hiding this comment

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

I like splitting this out to be shared, but am wondering why this needs to be part of an inheritance hierarchy, if it's effectively just a pure function accepting some inputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't need to be; I just implemented it this way.

Suppose you refactor this to be a non-method. In that case, you'll notice that both implementations pass their properties as the arguments, and these properties basically have the same name and (arguably) similar/same semantics.

I personally don't think about it as a "public" inheritance for the sake of this class' users, but more like a mix-in.

Existing programming languages are quite limiting in expressing such concepts, and often, an interface is the best thing you'll get.

In this case, the classes that implement this interface are "relatively" internal, so we've got the consequences under control, I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

This starts getting into territory of subjectivity, and this being structured as an interface is better than pure inheritance, but it means at the call-site of findEffectiveTypeface, we no longer know what state is actually an input to the algorithm, without looking up the interface et all.

In this case, where the state never changes over time, we've kinda just taken ReactTypefaceUtil, curried a couple params to a new function. Imo the indirection/boilerplate makes the code less easy to quickly reason about, instead of more (esp for ReactEditText).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This starts getting into territory of subjectivity,

It sure does

we no longer know what state is actually an input

It's nearly always the case with deduplication that the implementation details are taken away from you on the use site. You just assume that it does what it needs to do.

It can be argued both ways. When things are modeled as Ints or Strings, as it's the case in this project, you could also argue that an explicitly modeled mixin interface brings benefits, as it gives confidence that the right things are passed to the right places.

I was aware of the other way to model this, and I agree that it has some advantages. I decided to go this way.

Let me know if you consider this a blocker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add that the main reason I implemented this is that I add a third use later (if this changes anything).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I misinformed you. I ended up not adding a new implementation. But you can see how this interface is used in my work-in-progress implementation:

(relevant usage)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NickGerleman Did the real usage bring any new light here? Do you think we should "inline" the interface in this place?

Copy link
Contributor Author

@jakub-trzebiatowski jakub-trzebiatowski Feb 5, 2024

Choose a reason for hiding this comment

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

Also, could we clarify what you meant by...

I like splitting this out to be shared [...]

...? If we nuke the FontAttributeProvider interface, this whole PR is close to being a no-op, so I think we'd need to close it in such a case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NickGerleman Bump 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I still don't love the interface here.

@react-native-bot
Copy link
Collaborator

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@react-native-bot react-native-bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 21, 2024
@react-native-bot
Copy link
Collaborator

This PR was closed because it has been stalled for 7 days with no activity.

@react-native-bot react-native-bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants