
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
react-native-responsive-theme-provider
Advanced tools
`Dimensions` aware styled-components theme provider for responsive theming in react-native
Dimensions
aware styled-components theme provider for responsive theming in react-native
screen
and window
properties when orientation changesWhen building react-native applications there are different orientations
and different screen sizes that need to be supported. In order to detect
the resolution of the screen, we can use the react native Dimensions
API.
Using styled-components, it would be easy to do something like this:
import { Dimensions, Text } from 'react-native';
import { ThemeProvider } from 'styled-components/native';
const theme = {
bigColor: 'blue',
color: 'red',
screen: Dimensions.get('screen'),
window: Dimensions.get('window'),
};
const ThemedText = styled(Text)`
color: ${(props) => props.theme.screen.width > 800 ? props.theme.bigColor : props.theme.color}
`
const App = () => (
<ThemeProvider theme={theme}>
<ThemedText>Some text</ThemedText>
</ThemeProvider>
);
This is great, but what happens when the user goes from portrait to landscape? Using this code, the screen width will not update to the orientation change.
So the primary goal of this library to provide a theme that will update when the screen orientation changes.
All end-developers need to do is install the library
yarn add @very/react-native-theme-provider
import { Dimensions, Text } from 'react-native';
import ThemeProvider from 'react-native-responsive-theme-provider';
const theme = {
bigColor: 'blue',
color: 'red',
};
const ThemedText = styled(Text)`
color: ${(props) => props.theme.screen.width > 800 ? props.theme.bigColor : props.theme.color}
`
const App = () => (
<ThemeProvider theme={theme}>
<ThemedText>Some text</ThemedText>
</ThemeProvider>
);
Under the hood we are listening for Dimensions
changes and updating the theme
object
with new screen and width properties.
import { Text } from 'react-native';
import { ThemedStyledComponentsModule } from 'styled-components';
import styledComponents from 'styled-components/native';
import ThemeProvider, { ThemeDimensionProps } from 'react-native-responsive-theme-provider';
interface ThemeInterface {
bigColor: string;
color: string;
}
const { default: styled } = styledComponents as ThemedStyledComponentsModule<
ThemeInterface & ThemeDimensionProps
>;
const theme: ThemeInterface = {
bigColor: 'blue',
color: 'red',
};
// now we have typed support for props.theme
const ThemedText = styled(Text)`
color: ${(props) => props.theme.screen.width > 800 ? props.theme.bigColor : props.theme.color}
`
const App = () => (
<ThemeProvider theme={theme}>
<ThemedText>Some text</ThemedText>
</ThemeProvider>
);
alias for props.theme.screen
alias for props.theme.screen.width
alias from props.theme.window
alias from props.theme.window.width
import { Dimensions, Text } from 'react-native';
import ThemeProvider, { getScreenWidth } from 'react-native-responsive-theme-provider';
const theme = {
bigColor: 'blue',
color: 'red',
};
const ThemedText = styled(Text)`
color: ${(props) => getScreenWidth(props) > 800 ? props.theme.bigColor : props.theme.color}
`
const App = () => (
<ThemeProvider theme={theme}>
<ThemedText>Some text</ThemedText>
</ThemeProvider>
);
FAQs
`Dimensions` aware styled-components theme provider for responsive theming in react-native
We found that react-native-responsive-theme-provider demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.