TaqBostan / react-image-label

A comprehensive package for tagging images.
13 stars 5 forks source link

Pass init shapes doesn't work #1

Closed begonia666 closed 6 months ago

begonia666 commented 6 months ago

Hi

I am passing shapes from a redux state, the "imageUrl" can be changed dynamically without any problems but shapes cannot init after the ImageAnnotator receives shapes changes, seems like the component doesn't refresh itself

    <ImageAnnotator
        setHandles={setHandles}
        naturalSize={false}
        width={400}
        imageUrl={file?.url}
        shapes={file?.[FILE_FIELDS.SHAPES.NAME]}
        onContextMenu={showCategoriesDialog}
        onAdded={onAnnotationDraw}
        onReady={annotator => {
            annotatorRef.current = annotator
            annotator.drawRectangle()
        }}
    />

and for "onAdded" props, I tried to set a default category after shape drawn but the "annotator" is always undefined, I solved it by store it in a ref when "onReady" called

thank you for your time

TaqBostan commented 6 months ago

Hi,

I resolved both of the problems you mentioned. Please upgrade to the latest version (0.2.3) as soon as possible.

In the new version, primary shapes can be changed without any issues when changing imageUrl. Additionally, you can access annotator in onAdded or onContextMenu.

If you want to set a default category in onAdded, please use:

onAdded={shape => {annotator.updateCategories(shape.id, ["default category"])}}
begonia666 commented 6 months ago

Thank you so much, it works perfectly

TaqBostan commented 6 months ago

You're welcome. Thanks for creating this issue, I really appreciate it. The two bugs were critical.