Skip to content
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

'flex' property doesn't work with textRestyleFunctions #132

Closed
msvargas opened this issue Feb 23, 2022 · 6 comments
Closed

'flex' property doesn't work with textRestyleFunctions #132

msvargas opened this issue Feb 23, 2022 · 6 comments

Comments

@msvargas
Copy link

We found some inconsistency with textRestyleFunctions add flex property and it doesn't work I had to add layout restylefunction and it works

Example: (doesn't work for me v1.6.1)

<Text flex={1}>Test</Text>
import { layout, TextProps as RestyleTextProps, textRestyleFunctions } from '@shopify/restyle';

.....
const restyleFunctions = [...textRestyleFunctions, layout];
....
const props = useRestyle(restyleFunctions, rest);
@flexbox
Copy link

flexbox commented Mar 10, 2022

Hey @msvargas
Thank you for the issue, from my perspective it's not supported by intent

On the React Native documentation flexbox layout is used only for Views
https://reactnative.dev/docs/text-style-props

@msvargas
Copy link
Author

msvargas commented Mar 10, 2022

Hey @flexbox thank you for your answer but yes it supports all view styles, look at this:

https://reactnative.dev/docs/text#style

image
image

Also, other properties like position, top, left,bottom, right, flexShrink, ...etc doesn't work either

@flexbox
Copy link

flexbox commented Mar 11, 2022

😮 I didn't know that I always split Box and Text to don't overcomplicate things

@sbalay
Copy link
Contributor

sbalay commented Mar 27, 2022

Hey @msvargas

Text not support flex and other layout properties seems to be a decision made by design by previous maintainers, as layout is not included in textRestyleFunctions: https://github.com/Shopify/restyle/blob/master/src/createText.ts#L39

I guess the motivation was similar to what @flexbox mentioned above, and have a clear separation of resposibilities between Box and Text, but can't say for sure as I wasn't around back then.

If using typescript, you should get a type error when trying to apply flex to your Text component (before adding layout props to it.

Finally, If you do want layout props in your Text I think it's perfectly fine to add them manually as you did. 👍

@msvargas
Copy link
Author

msvargas commented May 5, 2022

Hi @sbalay thanks, I needed flexShrink to shrink the text well in some cases (for example with allowFontScaling equals to true) but also I agree with you about separating responsibilities

@RodolfoSilva
Copy link

Hey @msvargas

Text not support flex and other layout properties seems to be a decision made by design by previous maintainers, as layout is not included in textRestyleFunctions: https://github.com/Shopify/restyle/blob/master/src/createText.ts#L39

I guess the motivation was similar to what @flexbox mentioned above, and have a clear separation of resposibilities between Box and Text, but can't say for sure as I wasn't around back then.

If using typescript, you should get a type error when trying to apply flex to your Text component (before adding layout props to it.

Finally, If you do want layout props in your Text I think it's perfectly fine to add them manually as you did. 👍

import {Theme} from '@/theme';
import {createText} from '@shopify/restyle';
import {ComponentProps} from 'react';
import {TextStyle} from 'react-native';

const BaseText = createText<Theme>();

type Props = ComponentProps<typeof BaseText> &
  Pick<TextStyle, 'flex' | 'flexShrink' | 'flexGrow'>;

export default function Text(props: Props) {
  const {style, flex, flexGrow, flexShrink, ...rest} = props;
  return (
    <BaseText
      style={[
        {
          flex,
          flexGrow,
          flexShrink,
        },
        style,
      ]}
      {...rest}
    />
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants