react-native-responsive-fontSize icon indicating copy to clipboard operation
react-native-responsive-fontSize copied to clipboard

Problem with styled componets

Open yuriedmundo opened this issue 4 years ago • 5 comments

I'm having trouble using this library with Styled Components, has anyone had this problem?

yuriedmundo avatar Aug 23 '20 17:08 yuriedmundo

could you upload example code?

heyman333 avatar Aug 27 '20 08:08 heyman333

Styled use px as default unit.

No working (Only styled)

export const Text = styled.Text`
  flex: 1;
  font-weight: bold;
  font-size: ${RFValue(18, 580)};
  opacity: 0.78;
`;

// index.js
<Text allowFontScaling>
          {text}
</Text>

Solution:

Working (Mix styled + react style)

// style.js
export const Text = styled.Text`
  flex: 1;
  font-weight: bold;
  opacity: 0.78;
`;

// index.js
<Text allowFontScaling style={{fontSize: RFValue(18, 580)}}>
          {text}
</Text>

TiagoDanin avatar Nov 05 '20 12:11 TiagoDanin

Styled use px as default unit.

No working (Only styled)

export const Text = styled.Text`
  flex: 1;
  font-weight: bold;
  font-size: RFValue(18, 580);
  opacity: 0.78;
`;

// index.js
<Text allowFontScaling>
          {text}
</Text>

Solution:

Working (Mix styled + react style)

// style.js
export const Text = styled.Text`
  flex: 1;
  font-weight: bold;
  opacity: 0.78;
`;

// index.js
<Text allowFontScaling style={{fontSize: RFValue(18, 580)}}>
          {text}
</Text>

Your code is wrong, try this:

export const Text = styled.Text`
   flex: 1;
   font-weight: bold;
   font-size: ${RFValue(18, 580)}px;
   opacity: 0.78;
`;

albertoammar avatar Nov 07 '20 15:11 albertoammar

@TiagoDanin Have you tried? font-size: ${RFValue(18, 580)}px;

heyman333 avatar Nov 09 '20 06:11 heyman333

Your code is wrong, try this:

~@albertoammar it's not wrong... this is example of how some people expect can use ;)~

I put a wrong example, thanks. Update now

@TiagoDanin Have you tried? font-size: ${RFValue(18, 580)}px;

Yes this also work! but dp is different from px, recommend use in style prop.

I don't see it as a problem, just commented so you could know why of no working with styled.

TiagoDanin avatar Nov 17 '20 00:11 TiagoDanin