Skip to content

Commit

Permalink
feat(screen-orientation): add first draft of screen orientation hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Jun 16, 2019
1 parent 1c561d8 commit 6376e1f
Show file tree
Hide file tree
Showing 18 changed files with 11,989 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
- [**Permissions**](./packages/permissions)
- [`usePermissions`](./packages/permissions/docs/use-permissions.md) — get or ask permissions with [`Permissions`](https://docs.expo.io/versions/latest/sdk/permissions/)

- [**Screen Orientation**](./packages/screen-orientation)
- [`useScreenOrientation`](./packages/screen-orientation/docs/use-screen-orientation.md) — tracks changes in screen orientation with [`ScreenOrientation`](https://docs.expo.io/versions/latest/sdk/screen-orientation/)

- [**Sensors**](./packages/sensors)
- [`useAccelerometer`](./packages/sensors/docs/use-accelerometer.md) — tracks changes in acceleration with [`Accelerometer`](https://docs.expo.io/versions/latest/sdk/accelerometer/)
- [`useBarometer`](./packages/sensors/docs/use-barometer.md) — tracks changes in air pressure with [`Barometer`](https://docs.expo.io/versions/latest/sdk/barometer/)
Expand Down
2 changes: 1 addition & 1 deletion packages/brightness/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/permissions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions packages/screen-orientation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div align="center">
<h1>
<br />
screen orientation hooks
<br />
<br />
</h1>
<a href="https://github.com/bycedric/use-expo/releases">
<img src="https://img.shields.io/github/release/byCedric/use-expo/all.svg" alt="releases" />
</a>
<a href="https://travis-ci.com/byCedric/use-expo">
<img src="https://img.shields.io/travis/com/byCedric/use-expo/master.svg" alt="builds" />
</a>
<br />
<br />
<br />
<pre>npm i <a href="https://www.npmjs.com/package/@use-expo/screen-orientation">@use-expo/screen-orientation</a></pre>
<br />
</div>

- [`useScreenOrientation`](./docs/use-screen-orientation.md) &mdash; tracks changes in screen orientation with [`ScreenOrientation`](https://docs.expo.io/versions/latest/sdk/screen-orientation/)

<div align="center">
<br />
<br />
with :heart: <strong>byCedric</strong>
<br />
<br />
</div>
6 changes: 6 additions & 0 deletions packages/screen-orientation/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
65 changes: 65 additions & 0 deletions packages/screen-orientation/docs/use-screen-orientation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<div align="center">
<h1>
<br />
<code>useScreenOrientation</code>
<br />
<br />
</h1>
tracks changes in screen orientation with <a href="https://docs.expo.io/versions/latest/sdk/screen-orientation/"><code>ScreenOrientation</code></a>
<br />
</div>

## Examples

```jsx
// full hook
const [orientation, sizeClass] = useScreenOrientation();

// other options
useScreenOrientation({ get: false });
```

With the `useScreenOrientation` hook we can create a simple example.

```jsx
function ScreenOrientationExample() {
const [orientation, sizeClass] = useScreenOrientation();

return (
<View style={{ marginTop: 15, paddingHorizontal: 10 }}>
<Text>Screen orientation:</Text>
<Text>{orientation}</Text>
<Text>Screen size class: (only available on iOS)</Text>
<Text>{JSON.stringify(sizeClass, null, 2)}</Text>
</View>
);
}
```

## API

```ts
function useScreenOrientation(options?: ScreenOrientationOptions): [
ScreenOrientation.Orientation | undefined,
ScreenOrientationSizeClass | undefined,
];

interface ScreenOrientationOptions {
/** If it should fetch the screen orientation when mounted, defaults to `true` */
get?: boolean;
}

/** Both the horizontal and vertical size class, only available on iOS */
interface ScreenOrientationSizeClass {
horizontal: ScreenOrientation.SizeClassIOS;
vertical: ScreenOrientation.SizeClassIOS;
}
```

<div align="center">
<br />
<br />
with :heart: <strong>byCedric</strong>
<br />
<br />
</div>
14 changes: 14 additions & 0 deletions packages/screen-orientation/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const jestExpoPreset = require('jest-expo/jest-preset');
const { jsWithBabel: tsJestPreset } = require('ts-jest/presets');

module.exports = {
...jestExpoPreset,
clearMocks: true,
transform: {
...tsJestPreset.transform,
...jestExpoPreset.transform,
},
testMatch: [
'**/*.test.ts',
],
};
Loading

0 comments on commit 6376e1f

Please sign in to comment.