<commit_before>module UI
  class List < View
    class CustomListCell < UITableViewCell
      IDENTIFIER = "CustomListCell"

      def prepareForReuse
        super
        # this is far from optimal, we should find a better way
        # to achieve this
        self.contentView.subviews.each(&:removeFromSuperview)
      end

      def add_child(child)
        self.contentView.addSubview(child.container)
        child.width = self.contentView.bounds.size.width
        child.height = self.contentView.bounds.size.height
        child.update_layout
      end
    end

    def initialize
      super
      @data_source = []
      container.registerClass(CustomListCell, forCellReuseIdentifier: CustomListCell::IDENTIFIER)
    end

    def numberOfSectionsInTableView(table_view)
      1
    end

    def tableView(table_view, numberOfRowsInSection: section)
      @data_source.count
    end

    def tableView(table_view, cellForRowAtIndexPath: index_path)
      cell = table_view.dequeueReusableCellWithIdentifier(CustomListCell::IDENTIFIER, forIndexPath: index_path)
      content_view = @render_row_block.call(@data_source[index_path.row],
                                            index_path.row,
                                            index_path.section,
                                            {ui_table_view_cell: cell})
      cell.add_child(content_view)
      cell
    end

    def data_source=(data_source)
      @data_source = data_source
      container.reloadData
    end

    def render_row(&block)<commit_msg>[iOS] UI::List automatic row height calculation<commit_after>module UI
  class List < View
    class CustomListCell < UITableViewCell
      IDENTIFIER = "CustomListCell"

      attr_accessor :content_view

      def prepareForReuse
        super
        # TODO this is far from optimal, we should find a
        # better way to achieve this
        @content_view.children.each { |child| @content_view.delete_child(child) }
      end

      def add_child(child)
        @content_view = child
        self.contentView.addSubview(@content_view.container)
        @content_view.width = self.contentView.frame.size.width
        @content_view.update_layout
      end
    end

    def initialize
      super
      @data_source = []
      container.registerClass(CustomListCell, forCellReuseIdentifier: CustomListCell::IDENTIFIER)
      @sizing_cell = CustomListCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier: CustomListCell::IDENTIFIER)
    end

    def numberOfSectionsInTableView(table_view)
      1
    end

    def tableView(table_view, numberOfRowsInSection: section)
      @data_source.count
    end

    def tableView(table_view, heightForRowAtIndexPath: index_path)
      content_view = @render_row_block.call(@data_source[index_path.row],
                                            index_path.row,
                                            index_path.section,
                                            {ui_table_view_cell: @sizing_cell})
      @sizing_cell.add_child(content_view)
      @sizing_cell.content_view.layout[3]
    end

    def tableView(table_view, cellForRowAtIndexPath: index_path)
      cell = table_view.dequeueReusableCellWithIdentifier(CustomListCell::IDENTIFIER, forIndexPath: index_path)
      content_view = @render_row_block.call(@data_source[index_path.row],
                                            index_path.row,
                                            index_path.section,
                                            {ui_table_view_cell: cell})
      cell.add_child(content_view)
      cell
    end

    def data_source=(data_source)
      @data_source = data_source
      container.reloadData
    end

    def render_row(&block)
{'fraction_non_alphanumeric': 0.06566604127579738, 'fraction_numerical': 0.0008040739748056821, 'mean_word_length': 2.233968804159445, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7280986', 'n_tokens_mistral': 1029, 'n_tokens_neox': 993, 'n_words': 190}