react-native-responsive-screen icon indicating copy to clipboard operation
react-native-responsive-screen copied to clipboard

Fix listener in hooks

Open hoanglam10499 opened this issue 4 years ago • 7 comments

Solved Issues #69. Please merge

hoanglam10499 avatar Mar 13 '20 15:03 hoanglam10499

Solved Issues #69. Please merge

hoanglam10499 avatar May 19 '20 02:05 hoanglam10499

I think using a callback for the listenToOrientationChange would be a better choice. And you seem to be re-writing most of the file. I guess it's your formatter.

so consider something like.

`

if (typeof callback === 'function' ){
  const orientation = screenWidth < screenHeight ? 'portrait' : 'landscape';
  callback(orientation);

};`

Lesser code and solves the problem for functional and class based components.

Try refactoring your code, and make changes only to the lines that concerns your PR.

Cmion avatar May 21 '20 18:05 Cmion

@Cmion I didn't change all the files, it was a change of the format code. You can see the "File Changed".

Screen Shot 2020-05-22 at 08 47 26

hoanglam10499 avatar May 22 '20 01:05 hoanglam10499

Fix listener in hooks by hoanglam10499 · Pull Request #70 · marudy_react-native-responsive-screen - Google Chrome 5_22_2020 18_23_46 Fix listener in hooks by hoanglam10499 · Pull Request #70 · marudy_react-native-responsive-screen - Google Chrome 5_22_2020 18_24_02 Fix listener in hooks by hoanglam10499 · Pull Request #70 · marudy_react-native-responsive-screen - Google Chrome 5_22_2020 18_24_10

I'm not a maintainer, contributor or anything. But It seems like your recent commit made those changes.

Cmion avatar May 22 '20 17:05 Cmion

I also looks like the library needs some maintenance too

Cmion avatar May 22 '20 17:05 Cmion

@Cmion It was a change of the format code ...

hoanglam10499 avatar May 23 '20 09:05 hoanglam10499

Some quick, hopefully constructive, feedback on this PR:

  • to keep the PR clean, get rid of the commented out code. We have version control 😃
  • as @Cmion suggests in his post, consider using === for the comparison operator
  • I'd like to see this more explicit in terms of what parameter it is getting/using. Maybe have 2 parameters:
    const listenOrientationChange = ({classComponentThis = null, setStateHook = null}) => {
        // . . .
        if (classComponentThis) {
          classComponentThis.setState(...);
        } else if (setStateHook) {
          setStateHook(...);
        }
      }
    

Thank you for your efforts on this! Really, really appreciated.

gregfenton avatar Aug 07 '20 18:08 gregfenton