Categories
discuss

Animate view off Screen in android Constraint Layout

I have a TextView inside a Constraint Layout. I am trying to animate in a way that the view goes off the screen from top. This is what I did so far,

ConstraintSet constraintSet = new ConstraintSet();
ConstraintLayout layout = (ConstraintLayout)holder.mView;
constraintSet.clone(layout);

constraintSet.clear(R.id.txt_PackageTitle,ConstraintSet.TOP);
constraintSet.clear(R.id.txt_PackageDescription,ConstraintSet.TOP);  
constraintSet.clear(R.id.txt_PackageTitle,ConstraintSet.BOTTOM); 
constraintSet.clear(R.id.txt_PackageDescription,ConstraintSet.BOTTOM);

constraintSet.setMargin(R.id.txt_PackageTitle,ConstraintSet.TOP,-600); 
constraintSet.setMargin(R.id.txt_PackageDescription,ConstraintSet.TOP,-1200);

ChangeBounds transition = new ChangeBounds();
transition.setInterpolator(new BounceInterpolator());
transition.setDuration(600);                
TransitionManager.beginDelayedTransition(layout,transition);
                    constraintSet.applyTo(layout);

Now this code only moves the contents to the very top of the view, its not going out of the view and getting disappeared.

How can I do this with constraint layout?

Answer

Instead of clearing the bottom constraint of the TextView, try constraining its bottom to the top of the ConstraintLayout like this:

constraintSet.connect (R.id.txt_PackageTitle, 
            ConstraintSet.BOTTOM, 
            PARENT_ID, 
            ConstraintSet.TOP);

Now when the view is animated, it should slide off the top edge.

Negative margins are not supported with ConstraintLayout as is noted here.

Categories
discuss

Why is Espresso’s registerIdlingResources deprecated, and what replaces it?

I’m working on UI tests with Espresso for Android, and following the Google’s code sample it is used, even though it’s deprecated. So my questions are:

  • why is it deprecated?
  • what replaces it?

Answer

I’m working on unit tests with Espresso

I hope you mean UI tests 😉

why is it deprecated?

Some apps use build flavors in Gradle or a dependency injection framework, like Dagger, to generate test build configurations that register idling resources. Others simply expose the idling resource through their activities. The problem with all these approaches is that they add complexity to your development workflow, and some of them even break encapsulation.

what replaces it?

Now you need to use IdlingRegistry API

Source: Android Testing Support Library 1.0

Categories
discuss

How to pass props to component’s story?

I wanted to add some stories for vue-select component using Storybook, but I’m struggling with more complicated cases, which involve passing props or methods.

When I pass props inside the template it works:

storiesOf('VSelect', module)
.add('with labeled custom options', () => ({
        components: {VSelect},
        template:   `<v-select :options='[{value: "CA", label: "Canada"}, {value: "UK", label: "United Kingdom"}]' />`
    }))

I find it not very readable, so I wanted to pass them separately as props or data:

.add('with labeled custom options as props', () => ({
        components: {VSelect},
        props:      {options: [{value: "CA", label: "Canada"}, {value: "UK", label: "United Kingdom"}]},
        data:       {options: [{value: "CA", label: "Canada"}, {value: "UK", label: "United Kingdom"}]},
        template:   `<v-select />`
    }))

but neither data, nor props are not recognized by storybook – they seem to be ignored.

Answer

I’ve solved it.

.add('with labeled custom options as props', () => ({
        components: {VSelect},
        data() {
            return {
                options: [{value: "CA", label: "Canada"}, {value: "UK", label: "United Kingdom"}]
            }
        },
        template:   `<v-select :options="options" />`
    }))

There were 2 problems with my former approach:

  • Passed data was not wrapped in a function
  • I should have pass data only. Using both props and data seems to make Vue return a warning (The data property “options” is already declared as a prop.) and ignore passed data (even though it’s just a warning not an error, which I find odd)
Categories
discuss

Why does Typescript accept a number value as a type?

I had a bug in my Angular 4 project where I had declared a variable:

debounce: 300;

instead of

debounce = 300;

So of course this.debounce was undefined before the fix.

Shouldn’t Typescript give me an error in this case?

Answer

If you declare a variable with a type annotation of 300, that means not only is the type numeric, but only the value 300 is acceptable:

var debounce: 300;

You will get an error if you attempt to assign, say, 200:

debounce = 200;

Switch on strict null checks, and the compiler will catch this kind of problem (you meant to assign the value, not a type annotation):

var debounce: 200;

// Strict null checks tells you here that you have done something strange
var x = debounce;

In this case, when you try to use the variable, strict null checks points out you never assigned a value – thus telling you that you made an annotation, not an assignment.

Categories
discuss

text-overflow: ellipsis removes font-awesome icons

I have a simple table with font-awesome icons in their cells. I made the table columns resizable by using plain javascript. The cells content is hidden if overflown and an ellipsis (“…”) is shown:

td, th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

The Problem: When resizing the columns so that the content is hidden and then making it bigger again, all icons but the first are gone.

Expected behaviour: Icons should reappear when making the column bigger again.

Please run the snippet below to see it in action. Any help highly appreciated! Thanks.

(function makeTableHeaderResizable() {
  // clear resizers
  Array.prototype.forEach.call(
    document.querySelectorAll('.table-resize-handle'),
    function(elem) {
      elem.parentNode.removeChild(elem);
    }
  );

	// create resizers
  var thElm;
  var startOffset;
  Array.prototype.forEach.call(
    document.querySelectorAll('table th'),
    function(th) {
      th.style.position = 'relative';

      var grip = document.createElement('div');
      grip.innerHTML = '&nbsp;';
      grip.style.top = 0;
      grip.style.right = 0;
      grip.style.bottom = 0;
      grip.style.width = '5px';
      grip.style.position = 'absolute';
      grip.style.cursor = 'col-resize';
      grip.className = 'table-resize-handle';
      grip.addEventListener('mousedown', function(e) {
        thElm = th;
        startOffset = th.offsetWidth - e.pageX;
      });

      th.appendChild(grip);
    }
  );

  document.addEventListener('mousemove', function(e) {
    if (thElm) {
      thElm.style.width = startOffset + e.pageX + 'px';
    }
  });

  document.addEventListener('mouseup', function() {
    thElm = undefined;
  });
})();
/* text-overflow: ellipsis is likely causing the issue here */
td, th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
table {
  table-layout: fixed;
  border-top: 1px solid black;
  width: 100%;
}

/* styling */
th {
  border-right: 1px dotted red;
}
th {
  height: 50px;
}
td {
  border: 1px solid black;
}
tr {
  border-left: 1px solid black;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<h5>Drag the right border of the th elements and make the cells smaller. All fa-icons but the first have disappeared when you make the cells wider again.</h5>
<table>
  <thead>
    <tr>
      <th>Column</th>
      <th>Column</th>
      <th>Column</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        text works normally
      </td>
      <td>
        <i class="fa fa-cog"></i>
        <i class="fa fa-edit"></i>
        <i class="fa fa-trash"></i>
        <i class="fa fa-check"></i>
      </td>
      <td>
        <i class="fa fa-cog"></i>
        <i class="fa fa-edit"></i>
        <i class="fa fa-trash"></i>
        <i class="fa fa-check"></i>
      </td>
    </tr>
  </tbody>
</table>

Answer

You can set the display property of fa class to inline (working fiddle here):

td .fa {
  display: inline !important;
}
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..