react-native-modal-dropdown icon indicating copy to clipboard operation
react-native-modal-dropdown copied to clipboard

dropdown style not working

Open Cryton2017 opened this issue 7 years ago • 1 comments

Hello, I am trying to style the drop down to be perfectly inline and the same width as the original box. My drop down looks like:

<ModalDropdown 
            style={toysListStyle.CategoryPicker}
            dropdownStyle={toysListStyle.dropDownStyle}
            options={this.state.categoryOption} 
            defaultValue={this.state.categoryOption[0]}
            onSelect={(index) => this.LoadNewSearch("category", index)}
 />

The style is as follows:

const toysListStyle = StyleSheet.create({
    dropDownStyle: {
        position: "absolute",
        left: "0%",
        top: "0%",
    },
});

Cryton2017 avatar Sep 22 '18 08:09 Cryton2017

I was able to solve this problem like this by adding an onLayout event handler and calculating the width of the text input. Then applying that width using the adjustFrame callback. Something like this should work for you. This component doesn't like percentage widths. :)

const Dropdown = () => {
let newWidth = 0;    

function calcWidth(e) {
        newWidth = e.nativeEvent.layout.width;
    }

    return (
            <View style={styles.modalContainer}>
                <ModalDropdown
                    onLayout={event => calcWidth(event)}
                    adjustFrame={style => {
                        style.width = newWidth;
                        return style;
                    }}
                />
        </View>
    );
};

spence-s avatar Oct 07 '18 05:10 spence-s