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

MenuItem's text "jumps" at the start #5

Closed
xKRUTOIx opened this issue Oct 31, 2019 · 7 comments
Closed

MenuItem's text "jumps" at the start #5

xKRUTOIx opened this issue Oct 31, 2019 · 7 comments
Assignees
Labels
component: MenuItem Related to project's MenuItem component component: Text Related to React Native Text component wontfix This will not be worked on

Comments

@xKRUTOIx
Copy link

xKRUTOIx commented Oct 31, 2019

Hello, I've faced a problem: when a menu shows up text jumps a little at the very beginning and it looks ugly on real devices, (here's a demo that shows this visual bug, decrease speed to 0.5). The MenuItem is very simple, it has string variable and vector icon.

Although, the glitch disappears when I remove either string or icon from MenuItem (demo).

Code of the menu if it helps:
_mainMenu = () => (<Menu ref={(ref) => this.menuRef = ref} style={styles.menuStyles} > <MenuItem textStyle={styles.menuTextStyles} underlayColor={'#2C2B30'} onPress={() => { this.props.editMessage(this.props.message); this._hideMenu(this.menuRef); }}> {strings.edit} <SvgEditMessage /> </MenuItem> <MenuDivider color={'#676570'}/> <MenuItem textStyle={styles.menuTextStyles} underlayColor={'#2C2B30'} onPress={() => { this._hideMenu(this.menuRef); this._showMenu(this.deletionMenuRef, this.messageRef); }}> {strings.delete} <SvgTrashIcon/> </MenuItem> </Menu>);

@likern likern self-assigned this Oct 31, 2019
@likern
Copy link
Owner

likern commented Oct 31, 2019

@xKRUTOIx Could you provide simple app, which reproduces this issue? So I can run it and start debugging right away.

Something minimalistict, app with screen with one button, on tap on this button menu is showed up.

@xKRUTOIx
Copy link
Author

@likern Thanks for the answer.
Simple app snack code

@likern
Copy link
Owner

likern commented Nov 1, 2019

@xKRUTOIx I have not touched that part of code from original project https://github.com/mxck/react-native-material-menu. It looks like only Text is supported for MenuItem.

That's what I found on original page:

Children must be based on <Text> component (like text itself, strings, react-native-vector-icons or > expo icons) otherwise you may get an error on a real device

MenuItem is just a something rendered within a Text component:

<TouchableHighlight
      {...props}
      disabled={disabled}
      onPress={onPress}
      style={[styles.container, style]}
      underlayColor={underlayColor}
    >
      <Text
        ellipsizeMode={Platform.OS === 'ios' ? 'clip' : 'tail'}
        numberOfLines={1}
        style={[
          styles.title,
          disabled && { color: disabledTextColor },
          textStyle,
        ]}
      >
        {children}
      </Text>
    </TouchableHighlight>

I don't think (haven't work with react-native-svg extensively) it is legible to put svg inside text.

@likern likern added the enhancement New feature or request label Nov 1, 2019
@likern likern added this to the v0.7.0 milestone Nov 1, 2019
@likern
Copy link
Owner

likern commented Nov 1, 2019

My suggestion is for now do not consider MenuItem as a required element. Just copy paste it, modify as you want and use instead of MenuItem.

@xKRUTOIx
Copy link
Author

xKRUTOIx commented Nov 1, 2019

Ohh...I see, maybe it's better to ask in the original project then.

Although I've found this issue where the original project's author said that MenuItem treats vector icons as text, I've tried vector icon instead svg and I had the same glitch : (

Anyway, thanks for the answers!

@likern
Copy link
Owner

likern commented Nov 1, 2019

@xKRUTOIx It's more about how <Text /> is working in React Native. I think it doesn't work good with nesting other elements inside <Text /> like was pointed out in these bugs: facebook/react-native#25197, facebook/react-native#18826

You can inject string or other Text elements inside Text:

<Text style={styles.baseText}>
  <Text style={styles.titleText} onPress={this.onPressTitle}>
    {this.state.titleText + '\n\n'}
  </Text>
  <Text numberOfLines={5}>
    {this.state.bodyText}
  </Text>
</Text>

And https://github.com/oblador/react-native-vector-icons components are just standard Text - that's why they are working inside Text. https://github.com/react-native-community/react-native-svg is a native component, implementing SVG. It doesn't based on React Native Text component.

I think you can ask question in react-native-svg about putting SVG inside Text.

@xKRUTOIx
Copy link
Author

xKRUTOIx commented Nov 2, 2019

@likern You were right. I managed to solve this problem, I just used my custom component instead of MenuItem. Looks like you can close this issue.
Thanks a lot!

@likern likern added wontfix This will not be worked on and removed enhancement New feature or request labels Nov 2, 2019
@likern likern removed this from the v0.7.0 milestone Nov 2, 2019
@likern likern added component: Text Related to React Native Text component component: MenuItem Related to project's MenuItem component labels Nov 2, 2019
@likern likern closed this as completed Nov 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: MenuItem Related to project's MenuItem component component: Text Related to React Native Text component wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants