Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
kishannareshpal committed Feb 14, 2024
1 parent 3672443 commit a61a648
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 49 deletions.
15 changes: 10 additions & 5 deletions example/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ module.exports = function (api) {
extensions: ['.tsx', '.ts', '.js', '.json'],
alias: {
// For development, we want to alias the library to the source
'expo-sensor-fusion': path.join(__dirname, '..', 'src', 'index.ts'),
},
},
],
],
'@the-curve-consulting/expo-sensor-fusion': path.join(
__dirname,
'..',
'src',
'index.ts'
)
}
}
]
]
};
};
5 changes: 2 additions & 3 deletions example/src/lib/components/CameraController.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useThree } from '@react-three/fiber';
import { ExpoSensorFusion } from 'expo-sensor-fusion';
import { ExpoSensorFusion } from '@the-curve-consulting/expo-sensor-fusion';
import { useEffect, useRef } from 'react';
import { Matrix4 } from 'three';

Expand All @@ -12,16 +12,15 @@ export const CameraController = () => {
const rotationUpdateSubscription =
ExpoSensorFusion.addRotationUpdateListener((event) => {
const matrix = event.rotationMatrix;

matrixRef.current.set(
matrix.m11, matrix.m21, matrix.m31, 0, // eslint-disable-line prettier/prettier
matrix.m12, matrix.m22, matrix.m32, 0, // eslint-disable-line prettier/prettier
matrix.m13, matrix.m23, matrix.m33, 0, // eslint-disable-line prettier/prettier
0, 0, 0, 0 // eslint-disable-line prettier/prettier
);

camera.rotation.setFromRotationMatrix(matrixRef.current);
});

return () => {
rotationUpdateSubscription.remove();
};
Expand Down
2 changes: 1 addition & 1 deletion example/src/lib/components/FloatingBackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const FloatingBackButton = ({ onBack }: BackButtonProps) => {
<View
style={{
position: 'absolute',
top: 24,
top: 48,
left: 24
}}
>
Expand Down
4 changes: 1 addition & 3 deletions example/src/lib/components/ImperativeTextWithLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Text, TextInput, View } from 'react-native';

export type ImperativeTextWithLabelProps = {
label: string;
text: string;
};

export type ImperativeTextWithLabelRef = {
Expand Down Expand Up @@ -36,7 +35,7 @@ export type ImperativeTextWithLabelRef = {
export const ImperativeTextWithLabel = forwardRef<
ImperativeTextWithLabelRef,
ImperativeTextWithLabelProps
>(({ label, text }, ref) => {
>(({ label }, ref) => {
const textInputRef = useRef<TextInput>(null);

useImperativeHandle(
Expand Down Expand Up @@ -64,7 +63,6 @@ export const ImperativeTextWithLabel = forwardRef<
<TextInput
ref={textInputRef}
style={{ color: '#0A0908' }}
value={text}
editable={false}
pointerEvents="none"
multiline
Expand Down
59 changes: 28 additions & 31 deletions example/src/screens/ExpoSensorFusionDebugScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExpoSensorFusion } from 'expo-sensor-fusion';
import { useEffect, useRef, useState } from 'react';
import { SafeAreaView, Text, TextInput } from 'react-native';
import { ExpoSensorFusion } from '@the-curve-consulting/expo-sensor-fusion';
import { useEffect, useRef } from 'react';
import { SafeAreaView, Text, View } from 'react-native';
import { Matrix3 } from 'three';

import { FloatingBackButton } from '../lib/components/FloatingBackButton';
Expand Down Expand Up @@ -35,17 +35,17 @@ export const ExpoSensorFusionDebugScreen = ({
matrix.m13, matrix.m23, matrix.m33, // eslint-disable-line prettier/prettier
);

// textRef.current?.setText(
// `1,1:\t\t${matrix.m11}\n` + // eslint-disable-line
// `1,2:\t\t${matrix.m12}\n` + // eslint-disable-line
// `1,3:\t\t${matrix.m13}\n\n` + // eslint-disable-line
// `2,1:\t\t${matrix.m21}\n` + // eslint-disable-line
// `2,2:\t\t${matrix.m22}\n` + // eslint-disable-line
// `2,3:\t\t${matrix.m23}\n\n` + // eslint-disable-line
// `3,1:\t\t${matrix.m31}\n` + // eslint-disable-line
// `3,2:\t\t${matrix.m32}\n` + // eslint-disable-line
// `3,3:\t\t${matrix.m33}` // eslint-disable-line
// );
textRef.current?.setText(
`1,1:\t\t${matrix.m11}\n` + // eslint-disable-line
`1,2:\t\t${matrix.m12}\n` + // eslint-disable-line
`1,3:\t\t${matrix.m13}\n\n` + // eslint-disable-line
`2,1:\t\t${matrix.m21}\n` + // eslint-disable-line
`2,2:\t\t${matrix.m22}\n` + // eslint-disable-line
`2,3:\t\t${matrix.m23}\n\n` + // eslint-disable-line
`3,1:\t\t${matrix.m31}\n` + // eslint-disable-line
`3,2:\t\t${matrix.m32}\n` + // eslint-disable-line
`3,3:\t\t${matrix.m33}` // eslint-disable-line
);
});

return () => {
Expand All @@ -57,28 +57,25 @@ export const ExpoSensorFusionDebugScreen = ({
<SafeAreaView
style={{
flex: 1,
justifyContent: 'center',
padding: 24
justifyContent: 'center'
}}
>
<FloatingBackButton onBack={onBack} />

<ImperativeTextWithLabel
ref={textRef}
label="Rotation matrix:"
text="Waiting for data..."
/>
<View style={{ padding: 24 }}>
<ImperativeTextWithLabel ref={textRef} label="Rotation matrix:" />

<Text
style={{
textAlign: 'center',
marginTop: 12,
color: 'grey',
fontSize: 13
}}
>
Rotate your device (and/or yourself) around to see the values change.
</Text>
<Text
style={{
textAlign: 'center',
marginTop: 12,
color: 'grey',
fontSize: 13
}}
>
Rotate your device (and/or yourself) around to see the values change.
</Text>
</View>
</SafeAreaView>
);
};
4 changes: 2 additions & 2 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"compilerOptions": {
"strict": true,
"paths": {
"expo-sensor-fusion": ["../src/index"],
"expo-sensor-fusion/*": ["../src/*"]
"@the-curve-consulting/expo-sensor-fusion": ["../src/index"],
"@the-curve-consulting/expo-sensor-fusion/*": ["../src/*"]
}
}
}
4 changes: 3 additions & 1 deletion example/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ module.exports = async (env, argv) => {
{
...env,
babel: {
dangerouslyAddModulePathsToTranspile: ['expo-sensor-fusion']
dangerouslyAddModulePathsToTranspile: [
'@the-curve-consulting/expo-sensor-fusion'
]
}
},
argv
Expand Down
4 changes: 2 additions & 2 deletions 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 src/libs/enhanceSubscriptionWithCleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Subscription } from 'expo-modules-core';

/**
* Enhances a {@link Subscription} object with additional {@link cleanupCallback} function to run after the
* {@link subscription.remove} operation.
* {@link Subscription#remove} operation.
*
* @param subscription - The event emitter subscription reference.
* @param cleanupCallback - Additional callback after {@link Subscription#remove} is called on {@link subscription}.
Expand Down

0 comments on commit a61a648

Please sign in to comment.