Skip to content

Commit

Permalink
[sensors][docs] autogenerate DeviceMotion docs, types render tweaks (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Simek committed Oct 19, 2022
1 parent 22fce50 commit 02e1474
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 91 deletions.
2 changes: 1 addition & 1 deletion apps/native-component-list/src/screens/SensorScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class DeviceMotionSensor extends SensorBlock<Sensors.DeviceMotionMeasurement> {
{this.renderXYZBlock('Acceleration w/gravity', this.state.data.accelerationIncludingGravity)}
{this.renderABGBlock('Rotation', this.state.data.rotation)}
{this.renderABGBlock('Rotation rate', this.state.data.rotationRate)}
<Text>Orientation: {this.state.data.orientation}</Text>
<Text>Orientation: {Sensors.DeviceMotionOrientation[this.state.data.orientation]}</Text>
</View>
);
}
Expand Down
3 changes: 1 addition & 2 deletions docs/components/plugins/api/APIDataType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export const APIDataType = ({ typeDefinition, inline = true }: APIDataTypeProps)
const isIntersectionWithObject =
type === 'intersection' && types?.filter(typeDefinitionContainsObject).length;
const isUnionWithObject =
elementType &&
elementType.type === 'union' &&
(type === 'union' || (elementType && elementType.type === 'union')) &&
types?.filter(typeDefinitionContainsObject).length;
const isObjectWrapped =
type === 'reference' &&
Expand Down
2 changes: 1 addition & 1 deletion docs/components/plugins/api/APISectionUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export const resolveTypeName = (
return queryType.name;
} else if (type === 'literal' && typeof value === 'boolean') {
return `${value}`;
} else if (type === 'literal' && value) {
} else if (type === 'literal' && (value || (typeof value === 'number' && value === 0))) {
return `'${value}'`;
} else if (type === 'intersection' && types) {
return types
Expand Down
61 changes: 2 additions & 59 deletions docs/pages/versions/unversioned/sdk/devicemotion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sourceCodeUrl: 'https://github.com/expo/expo/tree/main/packages/expo-sensors'
packageName: 'expo-sensors'
---

import APISection from '~/components/plugins/APISection';
import { APIInstallSection } from '~/components/plugins/InstallSection';
import PlatformsSection from '~/components/plugins/PlatformsSection';

Expand All @@ -21,62 +22,4 @@ import PlatformsSection from '~/components/plugins/PlatformsSection';
import { DeviceMotion } from 'expo-sensors';
```

## Methods

### `DeviceMotion.isAvailableAsync()`

> You should always check the sensor availability before attempting to use it.
Returns whether the `DeviceMotion` API is enabled on the device.

On mobile web, you need to request permissions for a sensor in response to a user interaction (i.e. touch event) before you can use this module. For example, [`Accelerometer.requestPermissionsAsync()`](/versions/latest/sdk/accelerometer.mdx#accelerometerisavailableasync) If the `status` is not equal to `granted` then you should inform the end user that they may have to open settings.

On **web** this starts a timer and waits to see if an event is fired. This should predict if the iOS device has the **device orientation** API disabled in `Settings > Safari > Motion & Orientation Access`. Some devices will also not fire if the site isn't hosted with **HTTPS** as `DeviceMotion` is now considered a secure API. There is no formal API for detecting the status of `DeviceMotion` so this API can sometimes be unreliable on web.

#### Returns

- A promise that resolves to a `boolean` denoting the availability of the sensor.

### `DeviceMotion.addListener(listener)`

Subscribe for updates to DeviceMotion.

#### Arguments

- **listener (_function_)** -- A callback that is invoked when a
DeviceMotion update is available. When invoked, the listener is
provided a single argument that is an object containing following fields:

- **interval (_number_)** -- Interval at which data is obtained from the native platform. Expressed in **milliseconds**.

- **acceleration (_object_)** -- Device acceleration on the three axis as an object with x, y, z keys. Expressed in m/s<sup>2</sup>.

- **accelerationIncludingGravity (_object_)** -- Device acceleration with the effect of gravity on the three axis as an object with x, y, z keys. Expressed in m/s<sup>2</sup>.

- **rotation (_object_)** -- Device's orientation in space as an object with alpha, beta, gamma keys where alpha is for rotation around Z axis, beta for X axis rotation and gamma for Y axis rotation.

- **rotationRate (_object_)** -- Device's rate of rotation in space expressed in degrees per second (deg/s).

- **alpha (_number_)**: X axis rotation.
- **beta (_number_)**: Y axis rotation.
- **gamma (_number_)**: Z axis rotation.

- **orientation (_number_)** -- Device orientation based on screen rotation. Value is on of `0` (portrait), `90` (right landscape), `180` (upside down), `-90` (left landscape).

#### Returns

- A subscription that you can call `remove()` on when you
would like to unsubscribe the listener.

### `DeviceMotion.removeAllListeners()`

Remove all listeners.

### `DeviceMotion.setUpdateInterval(intervalMs)`

Subscribe for updates to DeviceMotion.

#### Arguments

- **intervalMs (_number_)** Desired interval in milliseconds between
DeviceMotion updates.
<APISection packageName="expo-device-motion" />

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/expo-sensors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [plugin] Migrate import from @expo/config-plugins to expo/config-plugins and @expo/config-types to expo/config. ([#18855](https://github.com/expo/expo/pull/18855) by [@brentvatne](https://github.com/brentvatne))
- Drop `@expo/config-plugins` dependency in favor of peer dependency on `expo`. ([#18595](https://github.com/expo/expo/pull/18595) by [@EvanBacon](https://github.com/EvanBacon))
- Export Expo Modules permissions related types. ([#19525](https://github.com/expo/expo/pull/19525) by [@Simek](https://github.com/Simek))
- DeviceMotion: Add `DeviceMotionOrientation` enum. ([#19599](https://github.com/expo/expo/pull/19599) by [@Simek](https://github.com/Simek))

## 11.4.0 — 2022-07-07

Expand Down
72 changes: 62 additions & 10 deletions packages/expo-sensors/build/DeviceMotion.d.ts

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

2 changes: 1 addition & 1 deletion packages/expo-sensors/build/DeviceMotion.d.ts.map

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

43 changes: 42 additions & 1 deletion packages/expo-sensors/build/DeviceMotion.js

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

0 comments on commit 02e1474

Please sign in to comment.