Add screen size to callback function of createStyleSheet #54
Closed
ngocle2497
started this conversation in
Feature Requests
Replies: 1 comment 2 replies
-
Hello @masonle2x2 , thank you for the proposal and your quick PR. Although I understand what you're trying to achieve, I am against this change for the following reasons:
Here is a sample of my code from a real-world project: import { Dimensions } from 'react-native'
const WINDOW_WIDTH = Dimensions.get('window').width
const WINDOW_HEIGHT = Dimensions.get('window').height
export enum Measurements {
WindowWidth = WINDOW_WIDTH as number,
WindowHeight = WINDOW_HEIGHT as number
} const stylesheet = createStyleSheet(theme => ({
box: {
width: (Measurements.WindowWidth - 32) / 3,
height: (Measurements.WindowHeight - 32) / 3,
backgroundColor: theme.colors.background
}
}) IIf you are building an app that allows horizontal layout, then it makes sense. However, I would like to postpone it for now for version 2.0. You will be able to access dimensions like this: const stylesheet = createStyleSheet(theme => ({
box: {
width: (UnistylesRuntime.screenWidth - 32) / 3,
height: (UnistylesRuntime.screenHeight - 32) / 3,
backgroundColor: theme.colors.background
}
}) It will be auto-updated on layout change by C++. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think this will useful when someone want to create box with 30% screen width, ...
ex:
Beta Was this translation helpful? Give feedback.
All reactions