Circular View with centered text
combining sizing, borderRadius, and centering.
set equal width and height, borderRadius to half that, then justifyContent and alignItems center to place the Text in the middle.
WHAT THIS TESTS This is a practical composition question: it confirms you can turn a box into a circle and center content using flexbox, combining several style properties correctly.
A GOOD ANSWER COVERS To make a circle, the parent View must be square, so width and height are equal, for example both 80. Then borderRadius must be at least half of that dimension, so 40 for an 80 box; setting it to half guarantees a perfect circle while a larger value is also clamped to a circle. To center the Text inside, the parent uses flex centering: justifyContent center handles the main axis and alignItems center handles the cross axis, so the child is centered both vertically and horizontally regardless of default column direction. The child Text typically gets textAlign center so wrapped lines stay centered, plus a color and fontSize. You usually do not need extra wrappers because a single Text child centers cleanly with parent flex alignment.
COMMON WRONG ANSWERS Setting borderRadius to a fixed small value that only rounds corners. Centering only with alignItems or only justifyContent, leaving the text off-center on one axis. Giving unequal width and height, producing an ellipse. Adding margins on the Text to fake centering, which is brittle.
LIKELY FOLLOW-UPS How would you make the circle scale with content? What if the text is long and wraps? How do borderRadius percentages behave?
ONE CONCRETE EXAMPLE A parent View styled width 80, height 80, borderRadius 40, justifyContent center, alignItems center, backgroundColor brand. Inside, a single Text with color white and textAlign center showing a letter or count. The result is a centered avatar-style circle, and changing both width and height together keeps it round.
Interview question
To render a View as a perfect circle of width and height 80 with centered text, which combination is correct?
- a.borderRadius 80 with only alignItems center on the parent
- b.borderRadius 20 with textAlign center on the child only
- c.borderRadius 40 with flexDirection row and no alignment set
- d.borderRadius 40 with justifyContent center and alignItems center on the parentCorrect
Why? this is the answer
A circle needs borderRadius equal to half the equal width and height (40 for an 80 box), and centering on both axes requires both justifyContent and alignItems set to center. Using only one alignment leaves the text off-center on the other axis.
Just read this? Test yourself on what you have been reading.
Read the original → reactnative.dev
- #react-native
- #styling
- #flexbox
- #borderradius
- #centering
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on react-native — each one lists the topics its interview covers.
See open roles