Skip to content
New issue

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

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

Already on GitHub? # to your account

Image is not rendering. Does anybody faced this problem? #66

Open
dipeshhkc opened this issue Feb 17, 2021 · 2 comments
Open

Image is not rendering. Does anybody faced this problem? #66

dipeshhkc opened this issue Feb 17, 2021 · 2 comments

Comments

@dipeshhkc
Copy link

"entityMap":{"0":{"type":"IMAGE","mutability":"MUTABLE","data":{"src":"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRWO_UAe27eAhTik2ggPbzKGQfuXD1oVosA_Q&usqp=CAU","height":"auto","width":"auto","alignment":"right"}}}

@dominykast
Copy link

did you solved this problem?

@CornerSkyless
Copy link

Here is my state.

{
  "blocks": [
    {
      "key": "c407s",
      "text": " ",
      "type": "atomic",
      "depth": 0,
      "inlineStyleRanges": [],
      "entityRanges": [{ "offset": 0, "length": 1, "key": 0 }],
      "data": {}
    }
  ],
  "entityMap": {
    "0": {
      "type": "IMAGE",
      "mutability": "IMMUTABLE",
      "data": {
        "url": "https://shanghai.aliyuncs.com/images/41600b6b-37be-4229-8adb-da4bfa4c6b7e.jpg",
        "name": "1668482961564_5",
        "type": "IMAGE",
        "meta": {
          "id": "images/41600b6b-37be-4229-8adb-da4bfa4c6b7e.jpg",
          "title": "c96fd0302923c17f7dcf2b8f859fdc50.jpg",
          "alt": "c96fd0302923c17f7dcf2b8f859fdc50.jpg",
          "loop": false,
          "autoPlay": false,
          "controls": false,
          "poster": ""
        }
      }
    }
  }
}

It works after I add a atomicHandler like this:

const atomicHandler = (item: any, entityMap: any): any => {
    for (let entityItem of item.entityRanges) {
      if (entityMap.hasOwnProperty(entityItem.key)) {
        const entity = entityMap[entityItem.key];
        console.log(entity);
        if (entity.type === 'IMAGE') {
          return (
            <Image
              source={{uri: entity.data.url}}
              width={100}
            />
          );
        }
      }
    }
    return null;
 };
getRNDraftJSBlocks({
            contentState: state,
            atomicHandler,
 }),

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants