-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
[Native UI Component] Calculation of width/height for custom native UI element? #2260
Comments
Sorry, don't see how apply that measure function. Even opposite, I need to provide it for my custom view.
|
Here's what you have to do in order var {
React,
NativeModules: {
UIManager
}
} = require('react-native');
class MyCustom extends React.Component {
...
}
|
I don't need to calculate location, but to create view without fixed width and height, like Text. Pavel.
|
Hi @aksonov - for a detailed request like this is would help a lot to post an example repository that people can clone and experiment with. 'm not sure I have enough information to act here and code would probably fill that gap |
Okey, here is my test repository: https://github.com/aksonov/TestApp SVG Path uses CGPathRef internally so it could get own height/width using
should be just
|
Finally, I've found that code from Image.ios.js, so maybe best way is to do the same - use another native iOS utility class to get height/width for SVG path and call it from render() method like done in Image.ios.js:
|
Sorry, that code doesn't help. Could you check test repository and my examples? I still can't find a way to get data from native UI component before rendering (to get width/height of svg element). |
Looks like magic is hidden within NativeMethodsMixin and its measure methods, but it is still not clear. Is there any documentation? UPD: I've found text calculation within Layout.c UPD2: Looks like it is done using RCTShadowText view for Text, so should i create own "shadow" view for my custom component which will calculate its size? |
Okey, finally i've found exactly what i need - create own RCTShadowView descendant, add shadowView factory method to my own RCTViewManager, override fillCSSNode method and do calculation within own RCTShadowView using C static function:
Maybe you could add it to documentation, because now it is pretty difficult to find out. |
That way solved issue for 'child' element, but not for composite parent - native View. I expected View will calculate its size automatically as it does for children Text, but it doesn't... Please provide correct way, looks like I've missed something. |
Okey, probably i don't understand how React Native Layout works, I can't wrap View nicely around Text too. I've created issue #2465 for it. |
I want to build iOS react native component - analog of Text, where width and height is not known, but calculated dynamically depending from its content. As I see from debugging, RCTText.drawRect method is called with calculated rect already, but my component is called with empty rect if i did not define sizes via styles.
How to define needed rect for custom View?
I know, it is not bug/issue, but it seems to be lack of documentation, so I'm asking here (i've asked the same at stack overflow, but looks like nobody knows there).
The text was updated successfully, but these errors were encountered: