Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unity itemtype (M2-7632) #879

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,10 @@ PODS:
- react-native-tcp-socket (6.0.6):
- CocoaAsyncSocket
- React-Core
- react-native-unity (1.0.10):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-video (5.2.1):
- React-Core
- react-native-video/Video (= 5.2.1)
Expand Down Expand Up @@ -1392,6 +1396,7 @@ DEPENDENCIES:
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- "react-native-skia (from `../node_modules/@shopify/react-native-skia`)"
- react-native-tcp-socket (from `../node_modules/react-native-tcp-socket`)
- "react-native-unity (from `../node_modules/@azesmway/react-native-unity`)"
- react-native-video (from `../node_modules/react-native-video`)
- react-native-webview (from `../node_modules/react-native-webview`)
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
Expand Down Expand Up @@ -1549,6 +1554,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/@shopify/react-native-skia"
react-native-tcp-socket:
:path: "../node_modules/react-native-tcp-socket"
react-native-unity:
:path: "../node_modules/@azesmway/react-native-unity"
react-native-video:
:path: "../node_modules/react-native-video"
react-native-webview:
Expand Down Expand Up @@ -1703,6 +1710,7 @@ SPEC CHECKSUMS:
react-native-safe-area-context: b97eb6f9e3b7f437806c2ce5983f479f8eb5de4b
react-native-skia: 8c3c1016dfb86ae82d61e08a16c7197ac2b58eed
react-native-tcp-socket: e724380c910c2e704816ec817ed28f1342246ff7
react-native-unity: 1a01286041cff06399765db822dcdf9e1ff71af3
react-native-video: c26780b224543c62d5e1b2a7244a5cd1b50e8253
react-native-webview: a9454e7b9a99dc4c3fc865fd92de3e95d2eb79d2
React-nativeconfig: d7af5bae6da70fa15ce44f045621cf99ed24087c
Expand Down
16 changes: 14 additions & 2 deletions src/entities/activity/lib/types/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export type ActivityItemType =
| 'Video'
| 'Checkbox'
| 'Date'
| 'Time';
| 'Time'
| 'Unity';

export type StabilityTrackerConfig = {
lambdaSlope: number;
Expand Down Expand Up @@ -213,6 +214,10 @@ type RadioConfig = {
}>;
};

type UnityConfig = {
file: string;
};

type PhotoConfig = null;

type VideoConfig = null;
Expand Down Expand Up @@ -241,6 +246,7 @@ export type ActivityItemConfig =
| VideoConfig
| TimeConfig
| FlankerItemSettings
| UnityConfig
| null;

type ActivityItemBase = {
Expand Down Expand Up @@ -273,6 +279,11 @@ interface AbTestActivityItem extends ActivityItemBase {
config: AbTrailsConfig;
}

interface UnityActivityItem extends ActivityItemBase {
inputType: 'Unity';
config: UnityConfig;
}

interface StabilityTrackerActivityItem extends ActivityItemBase {
inputType: 'StabilityTracker';
config: StabilityTrackerConfig;
Expand Down Expand Up @@ -403,7 +414,8 @@ export type ActivityItem =
| DateActivityItem
| PhotoActivityItem
| TimeActivityItem
| VideoActivityItem;
| VideoActivityItem
| UnityActivityItem;

export type ActivityDetails = {
id: string;
Expand Down
25 changes: 25 additions & 0 deletions src/entities/activity/model/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
TextItemDto,
TimeItemDto,
TimeRangeItemDto,
UnityItemDto,
VideoItemDto,
} from '@app/shared/api/services/ActivityItemDto';
import { ActivityDto } from '@app/shared/api/services/IActivityService';
Expand Down Expand Up @@ -104,6 +105,28 @@ function mapToDrawing(dto: DrawingItemDto): ActivityItem {
};
}

function mapToUnity(dto: UnityItemDto): ActivityItem {
return {
id: dto.id,
name: dto.name,
inputType: 'Unity',
config: {
file: dto.config.file,
},
timer: null,
order: dto.order,
question: dto.question,
isSkippable: false,
hasAlert: false,
hasScore: false,
isAbleToMoveBack: false,
hasTextResponse: false,
canBeReset: false,
hasTopNavigation: false,
isHidden: dto.isHidden,
};
}

function mapToAbTest(dto: ABTrailsItemDto): ActivityItem {
const config = dto.config;

Expand Down Expand Up @@ -747,6 +770,8 @@ export function mapToActivity(dto: ActivityDto): ActivityDetails {
return mapToDrawing(item);
case 'time':
return mapToTime(item);
case 'unity':
return mapToUnity(item);
}
}),
hasSummary: dto.scoresAndReports?.showScoreSummary ?? false,
Expand Down
18 changes: 5 additions & 13 deletions src/entities/unityView/ui/Unity.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
import { useEffect, useRef } from 'react';
import { FC, useEffect, useRef } from 'react';

import UnityView from '@azesmway/react-native-unity';

import { UnityProps } from './types';

interface IMessage {
gameObject: string;
methodName: string;
message: string;
}

interface Props {
config: {
config: {
radius: number;
width: number;
height: number;
};
deviceType: 'mobile' | 'tablet';
};
}
const Unity = (config: Props) => {
const Unity: FC<UnityProps> = ({ title, config }) => {
const unityRef = useRef<UnityView>(null);

useEffect(() => {
if (unityRef?.current) {
if (unityRef.current) {
const message: IMessage = {
gameObject: 'gameObject',
methodName: 'methodName',
Expand Down
8 changes: 8 additions & 0 deletions src/entities/unityView/ui/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type UnityConfig = {
file: string | null;
};

export type UnityProps = {
title?: string;
config: UnityConfig;
};
9 changes: 1 addition & 8 deletions src/features/pass-survey/lib/types/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,7 @@ type StabilityTrackerPayload = {
};

type UnityPayload = {
config: UnityScreenConfig;
deviceType: 'mobile' | 'tablet';
};

type UnityScreenConfig = {
radius: number;
width: number;
height: number;
file: string | null;
};

type SplashPayload = { imageUrl: string };
Expand Down
9 changes: 9 additions & 0 deletions src/features/pass-survey/model/pipelineBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ export function buildPipeline(activity: ActivityDetails): PipelineItem[] {
const pipeline: PipelineItem[] = filterHiddenItems(activity.items)
.map((item, index) => {
switch (item.inputType) {
case 'Unity': {
return {
id: item.id,
payload: item.config,
type: item.inputType,
timer: null,
} satisfies PipelineItem;
}

case 'AbTrails': {
return getAbTrailsPipeline(
item.id,
Expand Down
2 changes: 1 addition & 1 deletion src/features/pass-survey/ui/ActivityItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export function ActivityItem({
case 'Unity':
item = (
<Box flex={1}>
<UnityView config={pipelineItem.payload} />
<UnityView config={pipelineItem.payload} title={pipelineItem.id} />
</Box>
);
break;
Expand Down
24 changes: 20 additions & 4 deletions src/shared/api/services/ActivityItemDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export type ResponseType =
| 'text'
| 'time'
| 'timeRange'
| 'video';
| 'video'
| 'unity';

type Match = 'any' | 'all';

Expand Down Expand Up @@ -421,6 +422,12 @@ export type AbTrailsConfiguration = AbTrailsItemSettingsDto;

export type AbTrailsAnswerSettings = null;

type UnityAnswerSettings = null;

type UnityConfiguration = {
file: string;
};

type Configuration =
| TextConfiguration
| SingleSelectionRowsConfiguration
Expand All @@ -443,7 +450,8 @@ type Configuration =
| AbTestConfiguration
| StabilityTrackerConfiguration
| FlankerConfiguration
| AbTrailsConfiguration;
| AbTrailsConfiguration
| UnityConfiguration;

type AnswerSettings =
| TextAnswerSettings
Expand All @@ -466,7 +474,8 @@ type AnswerSettings =
| AbTestAnswerSettings
| StabilityTrackerAnswerSettings
| FlankerAnswerSettings
| AbTrailsAnswerSettings;
| AbTrailsAnswerSettings
| UnityAnswerSettings;

type ActivityItemDtoBase = {
id: string;
Expand Down Expand Up @@ -612,6 +621,12 @@ export interface ABTrailsItemDto extends ActivityItemDtoBase {
responseValues: AbTrailsAnswerSettings;
}

export interface UnityItemDto extends ActivityItemDtoBase {
responseType: 'unity';
config: UnityConfiguration;
responseValues: UnityAnswerSettings;
}

export type ActivityItemDto =
| TextItemDto
| ParagraphTextItemDto
Expand All @@ -634,4 +649,5 @@ export type ActivityItemDto =
| ABTrailsItemDto
| StabilityTrackerItemDto
| FlankerItemDto
| TimeItemDto;
| TimeItemDto
| UnityItemDto;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"@jridgewell/gen-mapping" "^0.3.5"
"@jridgewell/trace-mapping" "^0.3.24"

"@azesmway/react-native-unity@^1.0.10":
version "1.0.10"
resolved "https://registry.yarnpkg.com/@azesmway/react-native-unity/-/react-native-unity-1.0.10.tgz#4107aba30ac45d25a66a353e73227016fa6cfea7"
integrity sha512-CyqqeCyiTMoa79YCDkkOeqLhlWecksthGYb3Mj6L0tMjRsntILpdFlJSR+YjWYcScEOz4eCn5481IdK/SbYVRw==

"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.23.5", "@babel/code-frame@^7.24.1", "@babel/code-frame@^7.24.2":
version "7.24.2"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.24.2.tgz#718b4b19841809a58b29b68cde80bc5e1aa6d9ae"
Expand Down
Loading