Skip to content

🐛LaunchData is being ignored  #1

@grahamyesfit

Description

@grahamyesfit

What were you trying to do?

I have created a Lens using Snapchat's dynamic lens example as a starting point.

I tested the Lens in Lens Studio with a fallback datasource and the Lens was correctly showing the values.

I published the Lens and I'm viewing it in our App.

Reproduceable Code

//JavaScript code 

	const initialLaunchData = { 
		challenge: 'Return to Oz',
		duration: '... in 13 Days', 
		stats: ["22 Workouts", "13K calories burned", "30 miles"], 
		date: [2023, 12, 14]  
	};

    return (
        <>
            <CameraKit
                ref={ref}
                style={styles.container}
                isActive={active}
                initialCameraFacing="front"
                initialLens={{
                    id: route?.params?.lensId,
                    launchData: initialLaunchData,
                }}
                zoom={zoom}
                focus={focus}
                preset="hd-1280x720"
                lensGroups={[cameraKitSettings.lensGroupId]}
                onInitialized={() => {
                    console.log('onInitialized');
                }}
                onLensChanged={(_event) => {
                    // console.log(event);
                }}
                onPhotoTaken={(picture) => {
                    console.log({ picture });
                    navigation.navigate('SnapchatPreviewScreen', {
                        type: Enums.PREVIEW_TYPES.PHOTO,
                        path: picture.path,
                    });
                }}
                onVideoRecordingFinished={(video) => {
                    console.log({ video });
                    setIsVideoRecording(false);
                    navigation.navigate('SnapchatPreviewScreen', {
                        type: Enums.PREVIEW_TYPES.VIDEO,
                        path: video.path,
                    });
                }}
                onError={(error) => {
                    console.log('onError', error);
                }}
            />
//Lens manager code
//@input Component.Text challengeText;
//@input Component.Text durationText;
//@input Component.Text statsText;
//@input Component.Text dateText;

// This will use FallbackData if global.launchParams has not been filled out 
var launchParams = global.launchParams;

/* Storage accessors */
var challenge;
var duration;
var stats;
var date;  

var storageKeys = ["challenge","duration","stats", "date"]

/****************/
function getData() {
    if (launchParams) {
        if (launchParams.has(storageKeys[0]) &&
            launchParams.has(storageKeys[1]) &&
            launchParams.has(storageKeys[2]) &&
            launchParams.has(storageKeys[3])) {
            
            challenge = launchParams.getString(storageKeys[0]);
            duration = launchParams.getString(storageKeys[1]);
            stats = launchParams.getString(storageKeys[2]);
            date = launchParams.getStringArray(storageKeys[3]);
            return true;
        }
        
    return false;
    }
}

function populateFields() {
    
    script.challengeText.text = challenge;
    script.durationText.text = duration;
    
    for(var i in stats) {
        script.statsText.text += (parseInt(i) + 1) + ". " +stats[i] + '\n';
    }
    
    setDate();
}

function setDate() {
    
    if(date.length == 3 && date[1] <= 12) {
        script.dateText.text = global.localizationSystem.getDateFormatted(new Date(date[0], date[1] -1, date[2]));      
    } else {
        print("Error: Incorrect date passed in, should be [year, month, day]. Today's date will be used instead");
        script.dateText.text = global.localizationSystem.getDateFormatted(new Date());
    }
    
}


if(getData()) { 
    populateFields();
} else {
    print("Failed to get Data");

What happened instead?

The correct Lens is shown but the hardcoded values for the fields are shown, not the launchData values that were passed in.

Relevant log output

No response

Device

Pixel 7

Library Version

0.2.0

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions