Add StyleSheet.setStyleAttributePreprocessor#11138
Closed
brentvatne wants to merge 1 commit into
Closed
Conversation
Contributor
Contributor
|
One thing I didn't understand from the description: Are there use cases for this when not using Exponent? Could the code live in Exponent only? Why add it to RN? |
Collaborator
Author
|
@mkonicek - it's possible that some people might want to do this too, for example in our discussion around CRNA it has been brought up that we want the new project to support other clients. Other clients would likely need to do the same thing for their font apis. |
Contributor
|
👍 Thanks for the explanation Brent! @facebook-github-bot shipit |
Contributor
|
@mkonicek has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
ide
pushed a commit
to expo/react-native
that referenced
this pull request
Nov 30, 2016
Summary:
**Motivation**
On Exponent we load fonts dynamically and assign their native names by appending a session id, so that fonts from one Exponent "experience" do not clash with each other. So, before sending the `fontFamily` to native, we want to change it to the Exponent-scoped `fontFamily`.
Example:
```js
// Before rendering your app
StyleSheet.setStyleAttributePreprocessor('fontFamily', _processFontFamily);
function _processFontFamily(name) {
// Pass system fonts through
if (!name || Constants.systemFonts.indexOf(name) >= 0) {
return name;
}
if (!Font.isLoaded(name)) {
if (__DEV__) {
console.error(`${name} is not a system font and has not been loaded through Exponent.Font.loadAsync. If you intended to use a system font, make sure you typed the name correctly and that it is supported by the current operating system. If this is a custom font, be sure to load it with Exponent.Font.loadAsync`);
} else {
return 'system';
}
}
return `ExponentFont-
Closes facebook#11138
Differential Revision: D4245518
Pulled By: mkonicek
fbshipit-source-id: bd2452b1129d6675aa7b88e41351f8bb61fa20a3
facebook-github-bot
pushed a commit
that referenced
this pull request
Aug 25, 2022
Summary: from the original design of `StyleSheet.setStyleAttributePreprocessor()` in #11138, the overwriting warning shows when the existing preprocess is be overwritten. the behavior changes from 33b385825c72. This PR revises the logic back to original design. ## Changelog [Internal] [Fixed] - Show warning only when overwriting existing preprocessor in `StyleSheet.setStyleAttributePreprocessor()` Pull Request resolved: #34479 Test Plan: Unit Test ``` PASS Libraries/StyleSheet/__tests__/StyleSheet-test.js setStyleAttributePreprocessor ✓ should not show warning when set preprocessor first time (2 ms) ✓ should show warning when overwrite the preprocessor (1 ms) ``` Reviewed By: dmitryrykun Differential Revision: D38940676 Pulled By: cipolleschi fbshipit-source-id: 80cf30fff62f4a02c17f7f42b3260a6011d5fc82
dmytrorykun
pushed a commit
that referenced
this pull request
Sep 14, 2022
Summary: from the original design of `StyleSheet.setStyleAttributePreprocessor()` in #11138, the overwriting warning shows when the existing preprocess is be overwritten. the behavior changes from 33b385825c72. This PR revises the logic back to original design. ## Changelog [Internal] [Fixed] - Show warning only when overwriting existing preprocessor in `StyleSheet.setStyleAttributePreprocessor()` Pull Request resolved: #34479 Test Plan: Unit Test ``` PASS Libraries/StyleSheet/__tests__/StyleSheet-test.js setStyleAttributePreprocessor ✓ should not show warning when set preprocessor first time (2 ms) ✓ should show warning when overwrite the preprocessor (1 ms) ``` Reviewed By: dmitryrykun Differential Revision: D38940676 Pulled By: cipolleschi fbshipit-source-id: 80cf30fff62f4a02c17f7f42b3260a6011d5fc82
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
On Exponent we load fonts dynamically and assign their native names by appending a session id, so that fonts from one Exponent "experience" do not clash with each other. So, before sending the
fontFamilyto native, we want to change it to the Exponent-scopedfontFamily.Example:
See the tests for another example which always converts fontFamily to Wingdings.
I marked this function as experimental because it seems possible that the attribute API will change, and because I built this specifically for the above use case and others may need to expand the API to work in their case -- I did not attempt to anticipate how others would use it.
Test plan
Run
npm test. This does not impact any app that does not use the API.