Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wannaby/wanna-ui

Package Overview
Dependencies
Maintainers
8
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wannaby/wanna-ui

Wanna WEB-AR Preview component

  • 2.5.0-alpha.7
  • npm
  • Socket score

Version published
Weekly downloads
74
increased by19.35%
Maintainers
8
Weekly downloads
 
Created
Source

WANNA 3D Viewer for Handbags: Getting Started

WANNA 3D Viewer for handbags was specifically crafted to answer the industry's pain point — the high number of returns due to the wrong size of the bag. It provides users with a novel experience to understand the size and capacity of a bag and enables brands to showcase the product with the utmost realism. The WANNA 3D experience is designed to help clients make an informed shopping decision by exploring the product's size, dimensions, texture, and key attributes before purchase.

The WANNA 3D Viewer is delivered as a React component to be used together with the WANNA SDK for Web, which provides the core experiences. The 3D Viewer has a customizable UI that is easy to integrate into a webpage.

This document guides you through installing and using 3D Viewer.

System requirements

Supported environments:

  • iOS — both iPhone and iPad:
    • Safari 14 and later
    • Safari 14 (in-app) and later
    • Google Chrome on iOS 14.3 and later
  • Android — both smartphones and tablets:
    • Google Chrome 88 and later
    • Android WebView
    • Android Browser 103 and later
    • Samsung Internet 17.0 and later
  • Windows:
    • Google Chrome 103 and later
    • Mozilla Firefox 102 and later
    • Edge 103 and later
  • macOS:
    • Google Chrome 102 and later
    • Safari 15.4 and later
    • Mozilla Firefox 102 and later
  • Linux:
    • Google Chrome 102 and later

License

To work with WANNA SDK you need a license key. Contact our sales representative at account@wanna.fashion to get one.

Installation and use

Simple installation

To install the WANNA 3D Viewer, add both @wannaby/wanna-ui and @wannaby/wanna-sdk to your project dependencies:

yarn add @wannaby/wanna-ui @wannaby/wanna-sdk

Import and launch

  1. Import the WANNA UI component and its styles from wanna-ui.
  2. Import WANNA SDK to your project from wanna-sdk library.
  3. Launch the 3D viewer by calling the component and passing the following parameters:
    • license — Your license key received from the WANNA team.
    • mode — This parameter is reserved for future use. In this version, only wannaSdk.MODE_TYPE_3D works.
    • modelsType — This parameter is reserved for future use. In this version, only wannaSdk.MODEL_TYPE_BAG works.
    • models — The models list. The current version of the component only displays one model. If you specify several identifiers in the list, only the first one will be used.
Example
import wannaSDK from '@wannaby/wanna-sdk';
import WannaUI, { VIEW_MODE_MOBILE }  from '@wannaby/wanna-ui';
import '@wannaby/wanna-ui/styles.css';

<WannaUI
  wannaSdk={wannaSDK}
  models={[
    {
      id: 'model_id',
      brand: 'Brand Name',
      name: 'Model Name',
      price: '$ 1,200',
      pois: [
        '',
        'Text that will be displayed for the 2nd POI',
        'Text that will be displayed for the 3rd POI',
      ],
    },
  ]}
  license="your_license_key"
  mode={wannaSDK.MODE_TYPE_3D}
  modelsType={wannaSDK.MODEL_TYPE_BAG}
/>

Extended installation

By default, wanna-ui uses an iframe hosted by WANNA, but you can override it by including an iframe in your build and host it yourself.

Add the following rules into your Webpack configuration:

rules: [
  ...
  {
    test: /@wannaby\/wanna-sdk\/.*iframe.html$/,
    loader: 'file-loader',
  },
  {
    test: /@wannaby\/wanna-sdk\/.*core.js$/,
    loader: 'file-loader',
    options: {
      name: 'core.js',
    },
   },
]

If instead of Webpack you use Rollup JS or another module bundler, add similar rules to the configuration. Add core.js and iframe.html files to your public folder. Import iframe.html and core.js to your application and pass the iframeSrc prop to the Wanna UI component:

import wannaSDK from '@wannaby/wanna-sdk';
import WannaUI from '@wannaby/wanna-ui';
import wannaSdkIframe from '@wannaby/wanna-sdk/iframe.html';
import '@wannaby/wanna-sdk/core';
import '@wannaby/wanna-ui/styles.css';

<WannaUI
  wannaSdk={wannaSDK}
  iframeSrc={wannaSdkIframe}
  models={[
    {
      id: 'model_id',
      brand: 'Brand Name',
      name: 'Model Name',
      price: '$ 1,200',
      pois: [
        '',
        'Text that will be displayed for the 2nd POI',
        'Text that will be displayed for the 3nd POI',
      ],
    },
  ]}
  license="your_license_key"
  mode={wannaSDK.MODE_TYPE_3D}
  modelsType={wannaSDK.MODEL_TYPE_BAG}
/>

Configure the component

Required settings

When integrating the WANNA UI component, you always have to provide the following settings for it:

  • the imported SDK in the wannaSdk prop
  • the license string in the license prop; contact WANNA sales representative to get one
  • the identifier of the model that should be displayed in the 3D viewer, in the models prop

That is enough for 3D Viewer to function. But you may also want to manage the component appearance and change the behavior on button clicks.

Component appearance

Set the theme prop to handle the light and dark themes for the component. The theme will handle the color for the loading indicator and other elements, but you can also override it by setting the mainColor prop.

In addition, you can display your logo on the loading screen (logoURL prop).

The header and footer of the 3D Viewer and the loading screen are split off into separate components. If you prefer to replace the default header, footer, or loading screen, use the headerComponent, footerLeftComponent, footerRightComponent, or loadingComponent props. Here's how the components fit into the 3D Viewer:

default view of a 3D Viewer

Points of interest

If the 3D model provides points of interest that highlight the special details about the bag, you can choose up to three of these points to display and set the descriptions for each. However, you cannot choose which points of interest to display or reorder them. To display the first 1, 2, or 3 points of interest, pass 1, 2, or 3 string values to the pois field of the models prop. If you don't want to set a description for any of the points, pass an empty string "" instead. Here is how the description for the point of interest will look:

Point of interest with a description

If you pass fewer points of interest, fewer dots will be displayed in the lower part of the screen. If you don't use any points of interest, the 3D model will be displayed from the default camera angle configured within the model.

Handling events

WANNA UI component can inform you of the user's actions and SDK events happening in the 3D Viewer window. These events will be handled by WANNA UI (except onHeaderBackClick). However, you can use the callback functions described below to implement your own logic in addition to what WANNA SDK already does.

Implement the callback functions WANNA UI will call in different situations, and pass them to the corresponding props.

  • Handle the user's actions while viewing the model:
    • onHeaderBackClick — the user clicks the "back" button.
      Note: The "back" button will only be displayed in the 3D Viewer UI if you do implement this callback.
    • onModel3dPoiChanged — the user switches to a different point of interest view.
    • onModel3dShowReferences — the user requests the dimension rulers to be displayed.
  • Handle events during model loading:
    • onModelLoadingSuccess — the model is loaded successfully.
      Note: This event is raised when the model data is successfully downloaded, but it doesn't guarantee that the model has been already rendered on the view.
    • onModelLoading — the model loading is in progress.
  • Handle errors:
    • onError — general errors.
    • onModelLoadingFail — model loading failure.

Component reference

WANNA UI component supports the following props:

Prop NameTypeDescription
wannaSdkObject, requiredThe SDK instance you imported from @wannaby/wanna-sdk.
licenseString, requiredLicense key. Get it from the WANNA sales representative.
modelsArray, requiredModel to be displayed in the 3D viewer. This prop accepts an array, but only the first model in the list will be used. Set the model identifier and optionally tune its display settings in this prop. See more in Models Prop.
themewannaSDK.THEME_LIGHT | wannaSDK.THEME_DARKUI theme (default: wannaSDK.THEME_LIGHT).
Note: There is a known issue with Samsung browser on Android devices and the way it handles dark mode. To prevent the colors mix-ups and ensure the UI looks as intended, it's best to always set the dark theme by default in Samsung browser on Android devices.
mainColorStringCustom color for the loading indicator, specified by a hex code (example: #deff00). The default color is determined by the UI theme.
logoURLStringCustom logo image URL; if specified, this image will be displayed on the loading screen.
modelsTypewannaSDK.MODEL_TYPE_BAG, requiredAlways pass wannaSDK.MODEL_TYPE_BAG to work with handbags. No other values are supported.
modewannaSDK.MODE_TYPE_3D, requiredAlways pass wannaSDK.MODE_TYPE_3D to work with the 3D Viewer. No other values are supported.
iframeSrcStringPath to the iframe.html if you choose to host it on your own server.
headerComponentReact.ComponentCustom component for the page header. See Header component. If you don't set one, the page will have a header with the model name and price displayed in text.
footerLeftComponentReact.ComponentCustom component for the left half of the footer. If you don't set one, the lower left corner of the page will show plus / minus buttons on desktop and nothing on mobile.
footerRightComponentReact.ComponentCustom component for the right half of the footer. If you don't set one, the lower right corner of the page will show a "show dimensions" button.
loadingComponentReact.ComponentCustom loading component. If you don't set one, a simple progress indicator will be shown by default.
fontObjectCustom font for the interface, expressed as { file: string, family: string }; by default, Roboto Google font is used.
viewModeVIEW_MODE_DESKTOP | VIEW_MODE_MOBILEView mode for the component. Constants exported from @wannaby/wanna-ui (default: VIEW_MODE_MOBILE).
dimensionsUnitwannaSDK.MODE_3D_DIMENSIONS_CM | wannaSDK.MODE_3D_DIMENSIONS_INCHLength measurement unit for the size rulers: centimeters or inches. By default, wannaSDK.MODE_3D_DIMENSIONS_CM, centimeters are used.
showOnboardingBooleanSet to true to display a short tutorial on using 3D Viewer after the page is loaded. Default value: false.
labelsObjectLocalization object. If you would like to change the UI language, set the props of this object to strings in the target language. See Labels.
onError(error) => voidCalled when an error occurs.
onModelLoadingFail(modelId) => voidCalled when the model loading fails.
onModelLoadingSuccess(modelId) => voidCalled when the model is successfully downloaded, though not necessarily already rendered in the view.
onModelLoading(modelId) => voidCalled when model loading starts.
onHeaderBackClick() => voidCalled when the user clicks the "back" button in the header. If you don't set this callback, no "back" button will be displayed in 3D Viewer UI.
onModel3dPoiChanged({ poi, modelId }) => voidCalled when the user clicks on a point of interest and the view changes to it.
onModel3dShowReferences({ modelId }) => voidCalled when the user clicks on the dimensions button and the rulers are displayed around the model to let the user see its size.

Here's how the configurable components fit into the 3D Viewer:

default view of a 3D Viewer

Models prop

The model list (models prop) supports the following fields for each entry:

Field NameTypeDescription
idString, requiredModel identifier.
imageStringURL to image that will be displayed in the default loading screen.
nameStringName that will be displayed in the default header.
priceStringPrice that will be displayed in the default header.
pois[String | Null, ...]The descriptions of 3D model points of interest. Accepts up to three descriptions; if you add more to the list, they will be ignored. If you wish to add a point of interest without any description, pass an empty string to the corresponding array element. Note that this setting doesn't allow you to reorder or choose which points of interest to display: only the first three configured in the 3D model can be shown.

Header component

WANNA provides full flexibility to customize the provided UI. Use your own header component by passing it as a render-prop in the headerComponent prop. This component is used in the Wanna UI component and the error screen.

headerComponent will receive the following props:

Prop NameTypeDescription
appWasInitBooleanIndicates that the app is ready. When the app is in the error or rotate screens, this prop is false. It will only be set to true in the Wanna UI component after the app is successfully initialized.
nameStringModel name.
modelIDStringModel identifier.
styleObjectStyles object that should be applied to header root element.
modewannaSDK.MODE_TYPE_3DMode of SDK use. Currently can be only wannaSDK.MODE_TYPE_3D.
viewModeVIEW_MODE_DESKTOP | VIEW_MODE_MOBILECurrent view mode: desktop or mobile. Constants exported from @wannaby/wanna-ui.

Loading component

To match your website better, you can use your own custom loading component by passing it as render prop in the loadingComponent property. This component will be used in the main component during initialization and model loading.

loadingComponent will receive the following props:

Prop NameTypeDescription
childrenReact.NodeText for the loading screen.
progressNumberNumber from 0 to 100 that shows the model loading progress.
imageURLImage to be shown with the loading indicator.
loadingColorStringColor of loading indicator, specified by a hex code (example: #deff00).
themewannaSDK.THEME_LIGHT | wannaSDK.THEME_DARKUI theme.
modelsTypewannaSDK.MODEL_TYPE_BAGModel type to work with; currently can be only wannaSDK.MODEL_TYPE_BAG.
modewannaSDK.MODE_TYPE_3DMode of SDK initialization; currently can be only wannaSDK.MODE_TYPE_3D.
typeLOADING_TYPE_INIT | LOADING_TYPE_MODEL | LOADING_TYPE_MODE_CHANGETells the component at what loading stage the 3D Viewer is: initializing the library or loading the model. Use this setting to distinguish between loading screens for SDK initialization and model loading. Constants exported from @wannaby/wanna-ui.

FooterLeft and FooterRight components

You can fully customize the footer by using your own custom footer components and passing them as render props in the footerRightComponent and footerLeftComponent properties. These components are used in the main component footer when the component is initializing or a model is loading.

footerRightComponent and footerLeftComponent support the following props:

Prop NameTypeDescription
viewModeVIEW_MODE_DESKTOP | VIEW_MODE_MOBILECurrent view mode: desktop or mobile. Constants exported from @wannaby/wanna-ui.
screenInteractionBooleanIndicates that the user has touched the screen at the current moment.
on3dZoomOut() => voidZoom out (minus button) handler for desktop mode.
on3dZoomIn() => voidZoom in (plus button) handler for desktop mode.
onToggleReferences() => voidDimensions button handler.
modelObjectCurrent selected model object from the models list. Contains not only the model identifier, but all the other info passed for it in the models prop.
activeShowReferenceBooleanIndicates whether the dimension rulers are displayed at the moment.
onboardingIsRunningBooleanIndicates whether the tutorial is currently shown.

Labels

All the texts visible in the 3D Viewer UI are available as labels. You can pass your own values for these labels to edit them or change the interface language.

The default values are listed in the table:

Label nameDefault valueDescription
starting3dViewerStarting 3D ViewerThe header of the initialization screen.
useWiFiUse a Wi-Fi network to start fasterThe message on the initialization screen, shown only in mobile mode but doesn't check if the user is already connected to Wi-Fi.
rotateThePhoneFor3dRotate the phone to view in 3DTells the user to rotate their smartphone for correct screen orientation. 3D Viewer only works in portrait orientation.
loadingModelLoading modelShown during model download.
doubleClickToFocusDouble click to select focus pointDisplayed as a part of tutorial in desktop viewing mode.
doubleTapToFocusDouble tap to select focus pointDisplayed as a part of tutorial in mobile viewing mode.
pinchToZoomPinch to zoomDisplayed as a part of tutorial in mobile viewing mode.
canHoldFits insideThe header message for the inlet that shows which objects would fit into the bag.
somethingWentWrongSomething went wrong. But we're working on itGeneric error message.
pleaseComeBackLaterPlease come back laterGeneric error description.
cantDownloadModelCan't download the model.Error: failed to download the 3D model.
cantToggleDimensionsCan't toggle model dimensions.Error: failed to show dimension rulers.
cantZoomInTheModelCan't zoom in the model.Error: failed to zoom in.
cantZoomOutTheModelCan't zoom iout the model.Error: failed to zoom out.
cantResetTheModelCan't reset the model.Error: failed to change the model shown in 3D Viewer.
cantChangeTheModelViewpointCan't change the model viewpoint.Error: failed to rotate the model around the selected focus point.
noImageNo imageThis text is shown in place of any image that 3D Viewer is unable to load.

See the screens where the messages are displayed:

App screen or situationLabel name
3D Viewer initialization screenstarting3dViewer
useWiFi
Phone orientation screenrotateThePhoneFor3d
Loading screenloadingModel
Tutorial screendoubleClickToFocus
Tutorial screendoubleTapToFocus
Tutorial screenpinchToZoom
Dimensions screencanHold
Error screensomethingWentWrong
pleaseComeBackLater
Error popupcantDownloadModel
cantToggleDimensions
cantZoomInTheModel
cantZoomOutTheModel
cantResetTheModel
cantChangeTheModelViewpoint

3D Viewer launch example

Package.json

"wannaby/wanna-sdk": <version>,
"wannaby/wanna-ui": <version>

App.js

import wannaSDK from '@wannaby/wanna-sdk';
import WannaUI, { VIEW_MODE_DESKTOP } from '@wannaby/wanna-ui';
import '@wannaby/wanna-ui/styles.css';

const models = [
  {
    id: 'model_id',
    brand: 'Brand Name',
    name: 'Model Name',
    price: '$ 1,200',
    pois: [
      '',
      'Text that will be displayed for the 2nd POI',
      'Text that will be displayed for the 3rd POI',
    ],
  },
];

const license = 'license_string';

function App() {
  return (
    <div>
      <PreviewModels
        wannaSdk={wannaSDK}
        models={models}
        license={license}
        mode={wannaSDK.MODE_TYPE_3D}
        viewMode={VIEW_MODE_DESKTOP}
        modelsType={wannaSDK.MODEL_TYPE_BAG}
        theme={wannaSDK.THEME_LIGHT}
      />
    </div>
  );
}

export default App;

FAQs

Package last updated on 10 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc