Growing menu with scrollbar

I hate to ask such a generic question but I’m really stuck and super hoping someone can help me along the way. Here is the situation:

I’m making the GUI for a mobile app, portrait mode. I’m using canvas scalers to scale my canvasses with a reference width of 1080. This means I effectively don’t know the height of my screen space.

What I want to create is a menu with a variable amount of items. The menu must be anchored to the bottom (with an offset margin) and grow upwards. So far I’ve been able to manage this using VerticalLayoutGroup and anchoring the rect transform to the bottom.

But my last requirement is that if the content would grow too big, a scrollbar would appear. The definition of the content being too big is: if it would extend the (unknown) screen height ( minus the offset margin of course). I hope the following image illustrates this much clearer:

I have an isolated unity project here:

The problem is that the scrollview doesn’t expand. I fixed it eventually by stretching the scrollview and resizing the parent manually as items are added. I set the anchors to the maximum size and adjust the sizeDelta.

public class MenuScript : MonoBehaviour

    public int MenuItemCount;
    public GameObject MenuItemPrefab;
    public Transform MenuItemParent;

    private RectTransform _rectTransform;

    void Start()
        _rectTransform = GetComponent<RectTransform>();

        for (var i = 0; i <= MenuItemCount; i++)
            GameObject instance = Instantiate(MenuItemPrefab, MenuItemParent, false);
            instance.GetComponent<Text>().text = = "Item " + i;

            float size = instance.transform.GetComponent<RectTransform>().sizeDelta.y;
            TryExpandBy(size + 10);


           private void TryExpandBy(float size)
            var deltaY = _rectTransform.sizeDelta.y + size;
            if (deltaY > 0) deltaY = 0;
            _rectTransform.sizeDelta = new Vector2(_rectTransform.sizeDelta.x, deltaY);