最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Custom styling for MenuOption in React native popup menu - Stack Overflow

programmeradmin2浏览0评论

So I'm new to React (and JavaScript too for that matter). I'm creating an App using react native and currently trying to style my popup menu. (which looks like this: Popup menu image)

I want to change the style of the options (make the font size bigger and space them out and change the font color too). My code looks something like this:

<MenuProvider>
      <Menu >
        <MenuTrigger>
            <Image
              style={styles.menucontainer}
              resizeMode="contain"
              source={require('../assets/icon_more.png')}>
            </Image>
        </MenuTrigger>
        <MenuOptions optionsContainerStyle={styles.optionsstyle}>
          <MenuOption  text= 'About' />
          <MenuOption  text= 'Help & Feedback'/>
          <MenuOption  text= 'Sign Out'/>
        </MenuOptions>
      </Menu>
</MenuProvider>

After checking .js I found a prop customStyles. Just like I passed a styling object for MenuOptions as prop optionContainerStyle, I tried passing customStyles for MenuOption but that produced an error:

In this environment the sources for assign MUST be an object. This error is a performance optimization and not spec pliant.

Here is my styles code:

const styles = StyleSheet.create({
  optionsstyle:{
    marginTop:  height*32/dev_dimension.h,
    marginLeft: width*184/dev_dimension.w,
    backgroundColor: '#fafafa',
    width:  width*168/dev_dimension.w,
    height: height*160/dev_dimension.h,
    flexDirection: 'row',
    flex: 1,
    justifyContent: 'space-between',
  },
});

Can anyone tell what I'm doing wrong?

So I'm new to React (and JavaScript too for that matter). I'm creating an App using react native and currently trying to style my popup menu. (which looks like this: Popup menu image)

I want to change the style of the options (make the font size bigger and space them out and change the font color too). My code looks something like this:

<MenuProvider>
      <Menu >
        <MenuTrigger>
            <Image
              style={styles.menucontainer}
              resizeMode="contain"
              source={require('../assets/icon_more.png')}>
            </Image>
        </MenuTrigger>
        <MenuOptions optionsContainerStyle={styles.optionsstyle}>
          <MenuOption  text= 'About' />
          <MenuOption  text= 'Help & Feedback'/>
          <MenuOption  text= 'Sign Out'/>
        </MenuOptions>
      </Menu>
</MenuProvider>

After checking https://github./instea/react-native-popup-menu/blob/master/src/MenuOption.js I found a prop customStyles. Just like I passed a styling object for MenuOptions as prop optionContainerStyle, I tried passing customStyles for MenuOption but that produced an error:

In this environment the sources for assign MUST be an object. This error is a performance optimization and not spec pliant.

Here is my styles code:

const styles = StyleSheet.create({
  optionsstyle:{
    marginTop:  height*32/dev_dimension.h,
    marginLeft: width*184/dev_dimension.w,
    backgroundColor: '#fafafa',
    width:  width*168/dev_dimension.w,
    height: height*160/dev_dimension.h,
    flexDirection: 'row',
    flex: 1,
    justifyContent: 'space-between',
  },
});

Can anyone tell what I'm doing wrong?

Share Improve this question edited Jun 27, 2018 at 21:47 YakovL 8,40513 gold badges73 silver badges113 bronze badges asked Jun 27, 2018 at 18:08 kdivkdiv 331 silver badge8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

According to documentation the optionsContainerStyle are deprecated and I am not sure if they work properly. Try to use customStyles props instead as seen in StylingExample where you can find full example.

The thing is that customStyles is map of styles for different parts. Something like

<MenuOptions customStyles={{optionWrapper: { padding: 5}, optionText: styles.text}}>
发布评论

评论列表(0)

  1. 暂无评论