I am working on chat interface and want my chat log items to fit on screen when the window resizes. For the main list I'm using a FlatList
and each individual item is a separate Component.
To achieve this, I have subscribed to the resize
and fullscreenchange
events using the window.addEventLister
method but still cannot get resize in many cases such as when leaving or entering macOS Full screen mode.
Is there some other events I should subcribe to or follow a different approach. Is there a library that can give me all thee kinds of events in one place?
Code Snippet on Request:
Flat List Views:
export class ChatListItem extends React.Component {
componentDidMount = () => {
window.addEventListener("resize", this.forceUpdate);
window.addEventListener("fullscreenchange", this.forceUpdate);
//Is there anything wrong with doing it the above way?
};
componentWillUnmount = () => {
window.removeEventListener("resize", this.forceUpdate);
window.removeEventListener("fullscreenchange", this.forceUpdate);
};
render = () => {
//My Views which take size using flex:1 / window width and height
};
}
However the same screen has a input box (that I made into a different Component
for some reason) and that is able to resize with the same logic:
export class ChatInputBox extends React.Component {
componentDidMount = () => {
window.addEventListener("resize", this.forceUpdate);
window.addEventListener("fullscreenchange", this.forceUpdate);
};
componentWillUnmount = () => {
window.removeEventListener("resize", this.forceUpdate);
window.removeEventListener("fullscreenchange", this.forceUpdate);
};
render = () => {
//My Views which take size using flex:1 / window width and height
};
}