From 714810030062d5165933fb51353da8a717c3b4cf Mon Sep 17 00:00:00 2001 From: Carlos Chacon Date: Sat, 21 Sep 2024 15:03:27 -0600 Subject: [PATCH 1/2] add unity DTO, mapper, pipeline items --- ios/Podfile.lock | 8 ++++++ src/entities/activity/lib/types/activity.ts | 16 ++++++++++-- src/entities/activity/model/mappers.ts | 25 +++++++++++++++++++ src/features/pass-survey/lib/types/payload.ts | 9 +------ .../pass-survey/model/pipelineBuilder.ts | 9 +++++++ src/shared/api/services/ActivityItemDto.ts | 24 +++++++++++++++--- 6 files changed, 77 insertions(+), 14 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 14dffba12..e67923a8f 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -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) @@ -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`) @@ -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: @@ -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 diff --git a/src/entities/activity/lib/types/activity.ts b/src/entities/activity/lib/types/activity.ts index 4e45b6214..707e3dac8 100644 --- a/src/entities/activity/lib/types/activity.ts +++ b/src/entities/activity/lib/types/activity.ts @@ -27,7 +27,8 @@ export type ActivityItemType = | 'Video' | 'Checkbox' | 'Date' - | 'Time'; + | 'Time' + | 'Unity'; export type StabilityTrackerConfig = { lambdaSlope: number; @@ -213,6 +214,10 @@ type RadioConfig = { }>; }; +type UnityConfig = { + file: string; +}; + type PhotoConfig = null; type VideoConfig = null; @@ -241,6 +246,7 @@ export type ActivityItemConfig = | VideoConfig | TimeConfig | FlankerItemSettings + | UnityConfig | null; type ActivityItemBase = { @@ -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; @@ -403,7 +414,8 @@ export type ActivityItem = | DateActivityItem | PhotoActivityItem | TimeActivityItem - | VideoActivityItem; + | VideoActivityItem + | UnityActivityItem; export type ActivityDetails = { id: string; diff --git a/src/entities/activity/model/mappers.ts b/src/entities/activity/model/mappers.ts index 1b72378d0..41b5a21ea 100644 --- a/src/entities/activity/model/mappers.ts +++ b/src/entities/activity/model/mappers.ts @@ -33,6 +33,7 @@ import { TextItemDto, TimeItemDto, TimeRangeItemDto, + UnityItemDto, VideoItemDto, } from '@app/shared/api/services/ActivityItemDto'; import { ActivityDto } from '@app/shared/api/services/IActivityService'; @@ -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; @@ -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, diff --git a/src/features/pass-survey/lib/types/payload.ts b/src/features/pass-survey/lib/types/payload.ts index a2def4082..93c70696c 100644 --- a/src/features/pass-survey/lib/types/payload.ts +++ b/src/features/pass-survey/lib/types/payload.ts @@ -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 }; diff --git a/src/features/pass-survey/model/pipelineBuilder.ts b/src/features/pass-survey/model/pipelineBuilder.ts index 13b0a0e0c..512587619 100644 --- a/src/features/pass-survey/model/pipelineBuilder.ts +++ b/src/features/pass-survey/model/pipelineBuilder.ts @@ -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, diff --git a/src/shared/api/services/ActivityItemDto.ts b/src/shared/api/services/ActivityItemDto.ts index 1e0cb8866..deefa3325 100644 --- a/src/shared/api/services/ActivityItemDto.ts +++ b/src/shared/api/services/ActivityItemDto.ts @@ -26,7 +26,8 @@ export type ResponseType = | 'text' | 'time' | 'timeRange' - | 'video'; + | 'video' + | 'unity'; type Match = 'any' | 'all'; @@ -421,6 +422,12 @@ export type AbTrailsConfiguration = AbTrailsItemSettingsDto; export type AbTrailsAnswerSettings = null; +type UnityAnswerSettings = null; + +type UnityConfiguration = { + file: string; +}; + type Configuration = | TextConfiguration | SingleSelectionRowsConfiguration @@ -443,7 +450,8 @@ type Configuration = | AbTestConfiguration | StabilityTrackerConfiguration | FlankerConfiguration - | AbTrailsConfiguration; + | AbTrailsConfiguration + | UnityConfiguration; type AnswerSettings = | TextAnswerSettings @@ -466,7 +474,8 @@ type AnswerSettings = | AbTestAnswerSettings | StabilityTrackerAnswerSettings | FlankerAnswerSettings - | AbTrailsAnswerSettings; + | AbTrailsAnswerSettings + | UnityAnswerSettings; type ActivityItemDtoBase = { id: string; @@ -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 @@ -634,4 +649,5 @@ export type ActivityItemDto = | ABTrailsItemDto | StabilityTrackerItemDto | FlankerItemDto - | TimeItemDto; + | TimeItemDto + | UnityItemDto; From eb294a0402497169f67e521919fbbd0e7c2efee5 Mon Sep 17 00:00:00 2001 From: Carlos Chacon Date: Sat, 21 Sep 2024 15:27:57 -0600 Subject: [PATCH 2/2] pass pipeline item to unity view --- src/entities/unityView/ui/Unity.tsx | 18 +++++------------- src/entities/unityView/ui/types.ts | 8 ++++++++ src/features/pass-survey/ui/ActivityItem.tsx | 2 +- yarn.lock | 5 +++++ 4 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 src/entities/unityView/ui/types.ts diff --git a/src/entities/unityView/ui/Unity.tsx b/src/entities/unityView/ui/Unity.tsx index e55f54f27..e4d93238f 100644 --- a/src/entities/unityView/ui/Unity.tsx +++ b/src/entities/unityView/ui/Unity.tsx @@ -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 = ({ title, config }) => { const unityRef = useRef(null); useEffect(() => { - if (unityRef?.current) { + if (unityRef.current) { const message: IMessage = { gameObject: 'gameObject', methodName: 'methodName', diff --git a/src/entities/unityView/ui/types.ts b/src/entities/unityView/ui/types.ts new file mode 100644 index 000000000..ed4025fc6 --- /dev/null +++ b/src/entities/unityView/ui/types.ts @@ -0,0 +1,8 @@ +export type UnityConfig = { + file: string | null; +}; + +export type UnityProps = { + title?: string; + config: UnityConfig; +}; diff --git a/src/features/pass-survey/ui/ActivityItem.tsx b/src/features/pass-survey/ui/ActivityItem.tsx index ca1da604b..f1a9bbfd5 100644 --- a/src/features/pass-survey/ui/ActivityItem.tsx +++ b/src/features/pass-survey/ui/ActivityItem.tsx @@ -420,7 +420,7 @@ export function ActivityItem({ case 'Unity': item = ( - + ); break; diff --git a/yarn.lock b/yarn.lock index bd59a86e9..d8c774608 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"