Comments (17)
haha thks and sorry ;-) It's getStylesheet not getStyleSheet 🙈
from react-native-responsive-ui.
Hello @cjadhav,
Unfortunately, ResponsiveComponent has been deprecated. Could you update to the latest API? Sorry for the trouble.
from react-native-responsive-ui.
Sorry about that! Yes let me provide an update that is friendly for class components 😅
from react-native-responsive-ui.
Sorry I should have been clearer. You can use ResponsiveComponent again. Please refer to the documentation athttps://github.com/wcandillon/react-native-responsive-ui/blob/master/README.md
from react-native-responsive-ui.
Thanks @wcandillon for quick reply.
I'll update the source with latest methods.
from react-native-responsive-ui.
Hi @wcandillon,
I am facing new error. I have done the change for latest update.
using the useStylesheet
now my look like this,
import { useStylesheet } from "react-native-responsive-ui";
class MyComponent extends Component {
render(){
const respStyles = useStylesheet(staticStyle);
return (
<View style={respStyles.container}>
...
</View>
)
}
}
const staticStyle = [
{
query: { orientation: "portrait" },
style: {
container: {
flex: 1,
flexDirection: "column"
}
}
},
{
query: { orientation: "landscape" },
style: {
container: {
flex: 1,
flexDirection: "row"
}
}
}
];
export default MyComponent;
Whenever this component is called to render app crashes with following error,
Invariant Violation: Invariant Violation: Invariant Violation: Invariant Violation: Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)
Can you help to solve this ?
Some more details,
Using following configurations,
"react": "16.8.3",
"react-native": "0.59.9",
"react-native-responsive-ui": "2.0.2",
Thanks
from react-native-responsive-ui.
Hi @wcandillon,
Thanks for the fix but it's still broken for me.
Giving same error for v.2.1.0 also.
Tested on iPhone XR (iOS 12.2)
Please help me.
from react-native-responsive-ui.
Thanks @wcandillon.
Using ResponsiveComponent
to create class. But not sure how should I call getStyleSheet
to receive orientation based styles.
import { ResponsiveComponent, getStyleSheet } from "react-native-responsive-ui";
class MyComponent extends ResponsiveComponent {
render(){
const respStyles = getStyleSheet(staticStyle);
return (
<View style={respStyles.container}>
...
</View>
)
}
}
const staticStyle = [
{
query: { orientation: "portrait" },
style: {
container: {
flex: 1,
flexDirection: "column"
}
}
},
{
query: { orientation: "landscape" },
style: {
container: {
flex: 1,
flexDirection: "row"
}
}
}
];
export default MyComponent;
I am facing errors in this.
and not getting how to use query based stylesheet.
from react-native-responsive-ui.
@wcandillon, I have tried useStylesheet
as per documentation but gives hook error.
tried getStyleSheet
but not getting how to pass static styles to that function.
Your help is highly appreciable.
from react-native-responsive-ui.
@cjadhav can you try with getStyleSheet
as
const {width, height} = this.state;
const respStyles = getStyleSheet({width, height}, staticStyle);
from react-native-responsive-ui.
@wcandillon, sorry but above solution also failed.
It's giving me TypeError.
TypeError: (0 , _reactNativeResponsiveUi.getStyleSheet) is not a function
from react-native-responsive-ui.
@cjadhav could it be an issue with the cache of your package bundle?
from react-native-responsive-ui.
@wcandillon Tried with all cache clear/reset.
No luck. Giving same error.
Taking the height and width from Dimensions.get("window")
from react-native-responsive-ui.
Same error with V.2.1.1 from your latest module.
from react-native-responsive-ui.
sorry to hear that, can you send me the exact code snippet?
from react-native-responsive-ui.
@wcandillon, Sure.
This is code just removed the other business login.
import React, { Component } from "react";
import { StyleSheet, Text, View, Image, Platform, Animated, TextInput, ScrollView } from "react-native";
import { Dimensions, ImageBackground, TouchableOpacity, TouchableHighlight } from "react-native";
import { ResponsiveComponent, getStyleSheet } from "react-native-responsive-ui";
class Schedules extends ResponsiveComponent {
constructor(props) {
super(props);
this.state = {
height: Dimensions.get("window").height,
width: Dimensions.get("window").width
};
}
render() {
// const { respStyles } = this;
const { width, height } = this.state;
const respStyles = getStyleSheet({ width, height }, staticStyle);
return (
<View
style={styles.viewContainer}
onLayout={e => this.setState({ width: e.nativeEvent.layout.width, height: e.nativeEvent.layout.height })}
>
<View style={respStyles.viewHolder} />
</View>
);
}
}
const staticStyle = [
{
query: { orientation: "portrait" },
style: {
viewHolder: {
flex: 1,
flexDirection: "column"
}
}
},
{
query: { orientation: "landscape" },
style: {
viewHolder: {
flex: 1,
flexDirection: "row"
}
}
}
];
const styles = StyleSheet.create({
viewContainer: {
flex: 1,
flexDirection: "column",
backgroundColor: "#F0F0F0"
}
});
export default Schedules;
from react-native-responsive-ui.
@wcandillon, It worked.
Thank you so much for the help.
from react-native-responsive-ui.
Related Issues (20)
- Update to React 16 HOT 4
- Strategy for sending base64 to the DB? HOT 1
- Suggestion: Modify ResponsiveStyleSheet to behave like Platform.select HOT 5
- orientation query not respected? HOT 1
- Can you use the library with vanilla JS i.e. without flow? HOT 3
- Typescript Support? HOT 1
- Push latest version to npm HOT 1
- MediaQuery dimensions? HOT 1
- When I use typescript to develop, always met error by calling useDemission. HOT 5
- TypeError: TypeError: (0, _reactNativeResponsiveUi.getStyleSheet) is not a function. HOT 3
- Can't use in non-typescript codebases, all files seems to be .tx only HOT 4
- react-native-web official support HOT 3
- Provide @types for Typescript HOT 7
- Warning: componentWillMount has been renamed, and is not recommended for use HOT 1
- No matching version found. Unable to install react-native-responsive-ui > 2.0.0 HOT 2
- Update releases tab HOT 1
- getStylesheet causes media query styles to leak into original stylesheet
- [Discussion] v3 API Changes
- removing lodash dependency
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-responsive-ui.