divkit / divkit

DivKit is an open source Server-Driven UI (SDUI) framework. SDUI is a an emerging technique that leverage the server to build the user interfaces of their mobile app
https://divkit.tech
Other
2.26k stars 130 forks source link

What is the correct response format for apply the patch? #30

Closed hulygun closed 9 months ago

hulygun commented 1 year ago

I have config:

{
  "templates": {
    "main": {
      "type": "container",
      "height": {
        "type": "match_parent"
      },
      "visibility_action": {
        "log_id": "load_data",
        "url": "div-action://download?url=http://example.com/patch",
        "visibility_duration": 1,
        "visibility_percentage": 1
      }
    }
  },
  "card": {
    "log_id": "card",
    "states": [
      {
        "div": {
          "type": "main",
          "id": "main",
          "items": [
            {
              "type": "text",
              "id": "wellcome",
              "text": "wellcome"
            }
          ]
        },
        "state_id": 0
      }
    ]
  }
}

http://example.com/patch:

{
  "changes": [
    {
      "id": "main",
      "items": [
        {
          "type": "text",
          "id": "goodbye",
          "text": "goodbye"
        }
      ]
    }
  ]
}

In the logs I see that a request for a patch occurs but is not applied. Testing in DivKit Playground demo android

4eb0da commented 1 year ago

Hello! You need a templates field in the patch, even if it is empty

hulygun commented 1 year ago

That?

{
  "patch": {
       "changes": [...],
       "mode": "partial"
  },
  "templates": {}
}

In this form, throws out of the screen. Please get correct structure.

4eb0da commented 1 year ago

Please make sure that all json in the changes property uses only templates from the patch and not from the main card