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

      attr_accessor :content_view

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

    def initialize
      super
      @data_source = []
      @render_row_block = lambda { |section_index, row_index| ListRow }
      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)
      if !@sizing_cell.content_view
        content_view = @render_row_block.call(index_path.section, index_path.row).new
        @sizing_cell.content_view = content_view
      end
      @sizing_cell.content_view.update(@data_source[index_path.row])
      @sizing_cell.content_view.update_layout
      @sizing_cell.content_view.layout[3]
    end

    def tableView(table_view, cellForRowAtIndexPath: index_path)
      cell = table_view.dequeueReusableCellWithIdentifier(CustomListCell::IDENTIFIER, forIndexPath: index_path)
      if !cell.content_view
        content_view = @render_row_block.call(index_path.section, index_path.row).new
        cell.content_view = content_view
      end
      cell.content_view.update(@data_source[index_path.row])
      cell.content_view.update_layout
      cell
    end

    attr_reader :data_source

    def data_source=(data_source)
      @data_source = data_source
      container.reloadData
    end<commit_msg>support for multiple row classes, properly re-layout view cells when the table view resizes them<commit_after>module UI
  class List < View
    class CustomListCell < UITableViewCell
      IDENTIFIER = "CustomListCell"

      attr_reader :content_view

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

      def layoutSubviews
        @content_view.width = contentView.frame.size.width
        @content_view.update_layout
        super
      end
    end

    def initialize
      super
      @data_source = []
      @render_row_block = lambda { |section_index, row_index| ListRow }
    end

    def numberOfSectionsInTableView(table_view)
      1
    end

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

    def tableView(table_view, cellForRowAtIndexPath: index_path)
      row_klass = @render_row_block.call(index_path.section, index_path.row)
      cell_identifier = CustomListCell::IDENTIFIER + row_klass.name
      cell = table_view.dequeueReusableCellWithIdentifier(cell_identifier)
      unless cell
        cell = CustomListCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier: cell_identifier)
        cell.content_view = row_klass.new
      end
      cell.content_view.update(@data_source[index_path.row])
      cell.content_view.update_layout
      cell
    end

    def tableView(table_view, heightForRowAtIndexPath: index_path)
      cell = tableView(table_view, cellForRowAtIndexPath: index_path)
      cell.content_view.layout[3]
    end

    attr_reader :data_source

    def data_source=(data_source)
      if @data_source != data_source
        @data_source = data_source
        container.reloadData
      end
    end
{'fraction_non_alphanumeric': 0.06880127017729558, 'fraction_numerical': 0.0010584810796507012, 'mean_word_length': 3.359861591695502, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2058703', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1114, 'n_words': 200}