GithubHelp home page GithubHelp logo

Comments (8)

vjeux avatar vjeux commented on May 5, 2024

Nice find, do you want to take a stab at fixing it?

from yoga.

prenaux avatar prenaux commented on May 5, 2024

Yup, I've got the basics working now. Hacking in the C code atm, I'll put it back to JS once I'm done.

I've added support for alignContent since that's the root of the problem. I'm referring to http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#align-content-property for the specs, its a bit light on math, but I believe I got the algo part sorted out now.

There's still an issue though, which is that I need an array - at least as far as I can tell now - to keep the size & nodes of the lines (on the crossAxis) so that I can re-distribute them afterward when you use alignContent to distribute them in stretch mode. I'll try to see if I can rework the algo without needing it, but per the spec - and as I've observed in Chrome/IE/FF, in the case of 'stretch' the result is computed 'after the fact', basically the new "row" height is a function of the computed size of the elements within the div (hopefully that makes sense ;)).

So, I probably need to add some "API" to allocate/free the temporary array needed, seems it shouldn't be too problematic. Either an external API or another "interface" function (like measure/get_dirty) in the css node...

If you have any suggestion in that regard let me know.

from yoga.

vjeux avatar vjeux commented on May 5, 2024

Instead of allocating an array, can you add another field on the node object that you are going to use while doing the update? This way you don't need to allocate arrays, it's already allocated?

from yoga.

prenaux avatar prenaux commented on May 5, 2024

Yes, it should be possible to do the same thing by just adding a line_index field to the css_node, and then recomputing what's necessary in the multi-line + alignContent with fixed size case. I suppose that's a better option since the code is basically allocation free atm.

from yoga.

prenaux avatar prenaux commented on May 5, 2024

Submitted a pull request with the implementation, going to integrate in react-native and add more test cases in Jasmine next.

from yoga.

prenaux avatar prenaux commented on May 5, 2024

alignContent is 'stretch' by default, same as alignItems and as Chrome/Specs. However the previous version of the code was behaving more like flex-start not sure if its better to be more like the previous behavior or to follow the specs...

from yoga.

prenaux avatar prenaux commented on May 5, 2024

A react component that 'tests' alignContent:

var React = require('react-native');
var {
  StyleSheet,
  Text,
  View,
  TouchableHighlight
} = React;

var styles = StyleSheet.create({
  container: {
    backgroundColor: '#333333',
    width: 300,
    height: 380,
    flexDirection: 'row',
    flexWrap: 'wrap',
    padding: 3,
  },
  box: {
    backgroundColor: '#ffffff',
    width: 50,
    height: 50,
    margin: 10,
  },
  box2: {
    backgroundColor: '#ffffff',
    width: 50,
    height: 100,
    margin: 10,
  },
  lighter_grey: {
    backgroundColor: '#606060',
  },
  red: {
    backgroundColor: '#ff0000',
  },
  green: {
    backgroundColor: '#00ff00',
  },
  cyan: {
    backgroundColor: '#00ffff',
  },
  button: {
    margin: 5,
    fontWeight: 'normal',
  },
  selected: {
    fontWeight: '800',
  },
});

module.exports = React.createClass({
  getInitialState: function() {
    return {
      alignItems: 'flex-start',
      alignContent: 'stretch'
    };
  },

  alignItems: function(aNewAlignItems) {
    this.setState({
      alignItems: aNewAlignItems
    });
  },

  alignContent: function(aNewAlignContent) {
    this.setState({
      alignContent: aNewAlignContent
    });
  },

  render: function() {
    var button = (aName,aKind) => {
      return (
        <TouchableHighlight onPress={() => { this[aKind](aName) } }>
          <Text style={[
                styles.button,
                this.state[aKind] == aName ? styles.selected : undefined
                ]}>
            {aName}
          </Text>
        </TouchableHighlight>
      );
    }

    return (
      <View>
        <View style={
              [styles.container,{
               alignItems: this.state.alignItems,
               alignContent: this.state.alignContent
              }]}>
          <View style={[styles.box,styles.red]}><Text>0</Text></View>
          <View style={[styles.box,styles.red]}><Text>1</Text></View>
          <View style={[styles.box,styles.red]}><Text>2</Text></View>
          <View style={[styles.box,styles.red]}><Text>3</Text></View>
          <View style={[styles.box2,styles.red]}><Text>4</Text></View>
          <View style={[styles.box,styles.green,{alignSelf:'flex-start'}]}><Text>5</Text></View>
          <View style={[styles.box,styles.green]}><Text>6</Text></View>
          <View style={[styles.box2,styles.green]}><Text>7</Text></View>
          <View style={[styles.box,styles.green]}><Text>8</Text></View>
          <View style={[styles.box,styles.green]}><Text>9</Text></View>
          <View style={[styles.box,styles.cyan,{alignSelf:'flex-start'}]}><Text>10</Text></View>
          <View style={[styles.box,styles.cyan]}><Text>11</Text></View>
          <View style={[styles.box,styles.cyan]}><Text>12</Text></View>
          <View style={[styles.box,styles.cyan,{alignSelf:'flex-start'}]}><Text>13</Text></View>
          <View style={[styles.box,styles.cyan,{alignSelf:'stretch'}]}><Text>14</Text></View>
        </View>
        <View style={{flexDirection:'row'}}>
          <View style={{flex:0.5}}>
            <Text>AlignItems:</Text>
            {button('flex-start','alignItems')}
            {button('center','alignItems')}
            {button('flex-end','alignItems')}
            {button('stretch','alignItems')}
          </View>
          <View style={{flex:0.5}}>
            <Text>AlignContent:</Text>
            {button('flex-start','alignContent')}
            {button('center','alignContent')}
            {button('flex-end','alignContent')}
            {button('stretch','alignContent')}
          </View>
        </View>
      </View>
    );
  }
});

from yoga.

prenaux avatar prenaux commented on May 5, 2024

#79 has been merge, so closing this.

from yoga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.