GithubHelp home page GithubHelp logo

Comments (17)

wcandillon avatar wcandillon commented on June 15, 2024 3

haha thks and sorry ;-) It's getStylesheet not getStyleSheet 🙈

from react-native-responsive-ui.

wcandillon avatar wcandillon commented on June 15, 2024 1

Hello @cjadhav,

Unfortunately, ResponsiveComponent has been deprecated. Could you update to the latest API? Sorry for the trouble.

from react-native-responsive-ui.

wcandillon avatar wcandillon commented on June 15, 2024 1

Sorry about that! Yes let me provide an update that is friendly for class components 😅

from react-native-responsive-ui.

wcandillon avatar wcandillon commented on June 15, 2024 1

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.

cjadhav avatar cjadhav commented on June 15, 2024

Thanks @wcandillon for quick reply.
I'll update the source with latest methods.

from react-native-responsive-ui.

cjadhav avatar cjadhav commented on June 15, 2024

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.

cjadhav avatar cjadhav commented on June 15, 2024

Hi @wcandillon,

Thanks for the fix but it's still broken for me.
Giving same error for v.2.1.0 also.

Simulator Screen Shot - iPhone Xʀ - 2019-06-20 at 19 06 56

Tested on iPhone XR (iOS 12.2)

Please help me.

from react-native-responsive-ui.

cjadhav avatar cjadhav commented on June 15, 2024

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.

cjadhav avatar cjadhav commented on June 15, 2024

@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.

wcandillon avatar wcandillon commented on June 15, 2024

@cjadhav can you try with getStyleSheet as

    const {width, height} = this.state;
    const respStyles = getStyleSheet({width, height}, staticStyle);

from react-native-responsive-ui.

cjadhav avatar cjadhav commented on June 15, 2024

@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.

wcandillon avatar wcandillon commented on June 15, 2024

@cjadhav could it be an issue with the cache of your package bundle?

from react-native-responsive-ui.

cjadhav avatar cjadhav commented on June 15, 2024

@wcandillon Tried with all cache clear/reset.
No luck. Giving same error.
Screenshot 2019-06-20 at 10 56 40 PM

Taking the height and width from Dimensions.get("window")

from react-native-responsive-ui.

cjadhav avatar cjadhav commented on June 15, 2024

Same error with V.2.1.1 from your latest module.

from react-native-responsive-ui.

wcandillon avatar wcandillon commented on June 15, 2024

sorry to hear that, can you send me the exact code snippet?

from react-native-responsive-ui.

cjadhav avatar cjadhav commented on June 15, 2024

@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.

cjadhav avatar cjadhav commented on June 15, 2024

@wcandillon, It worked.
Thank you so much for the help.

from react-native-responsive-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.